src/Access/CustomParameterNamesAccessCheck.php | 9 +-------- src/JsonApiSpec.php | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Access/CustomParameterNamesAccessCheck.php b/src/Access/CustomParameterNamesAccessCheck.php index 3632003..46864ee 100644 --- a/src/Access/CustomParameterNamesAccessCheck.php +++ b/src/Access/CustomParameterNamesAccessCheck.php @@ -52,14 +52,7 @@ class CustomParameterNamesAccessCheck implements AccessInterface { $valid = TRUE; foreach (array_keys($json_api_params) as $name) { - // First, ensure this does not violate "MUST NOT". - if (strpbrk($name, JsonApiSpec::MEMBER_NAME_RESERVED_CHARACTERS)) { - $valid = FALSE; - break; - } - - // Second, ensure this complies with "MUST". - if (!preg_match(JsonApiSpec::MEMBER_NAME_REGEXP, $name, $m)) { + if (!JsonApiSpec::isValidMemberName($name)) { $valid = FALSE; break; } diff --git a/src/JsonApiSpec.php b/src/JsonApiSpec.php index f8615c8..6679245 100644 --- a/src/JsonApiSpec.php +++ b/src/JsonApiSpec.php @@ -10,15 +10,6 @@ namespace Drupal\jsonapi; final class JsonApiSpec { /** - * Member name: reserved characters. - * - * For use with \strpbrk(). - * - * @see http://jsonapi.org/format/#document-member-names - */ - const MEMBER_NAME_RESERVED_CHARACTERS = "+,.[]!\"#$%&'()*/:;<=>?@\\^`{}~|\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA\xB\xC\xD\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F"; - - /** * Member name: globally allowed characters. * * U+0080 and above (non-ASCII Unicode characters) are allowed, but are not @@ -66,4 +57,18 @@ final class JsonApiSpec { ')?' . '$/u'; + /** + * Checks whether the given member name is valid. + * + * @param string $member_name + * A member name to validate. + * + * @return bool + * + * @see http://jsonapi.org/format/#document-member-names + */ + public static function isValidMemberName($member_name) { + return preg_match(JsonApiSpec::MEMBER_NAME_REGEXP, $member_name) === 1; + } + }