Discovered as part of #2935947: Comply with code standards.
Specifically, {1} only matches a single occurrence of a character, + is for "one or more".
// First character must be "globally allowed". Length must be >=1.
self::MEMBER_NAME_GLOBALLY_ALLOWED_CHARACTER_CLASS . '{1}' .
'(' .
// As many non-globally allowed characters as desired.
self::MEMBER_NAME_INNER_ALLOWED_CHARACTERS . '*' .
// If length > 1, then it must end in a "globally allowed" character.
self::MEMBER_NAME_GLOBALLY_ALLOWED_CHARACTER_CLASS . '{1}' .
Overall, this is an especially hard to read bit of code regardless. See #2935947-24: Comply with code standards.
Any patch should also address code standard violations.
Comments
Comment #2
gabesulliceUpdate IS per #2935947-24: Comply with code standards
Comment #3
gabesulliceComment #4
wim leersI introduced that code in #2829328: Clean up Drupal\jsonapi\Access\CustomParameterNames and make it follow the spec more closely.
Comment #5
wim leersHappy to make it more legible. But code that checks spec conformity is bound to be hard to read. That's why it references http://jsonapi.org/format/#document-member-names!
So you're referring to that first line of code that you quoted, right?
Comment #6
gabesulliceDefinitely. And it's regex too! I'm really referring to the concatenation across multiple lines. E.g. a
sprintfmight be a clearer way to do this and pass code sniffs :)Yep, and it's totally possible that I'm misreading the regular expression because of rules that come later in the expression.
Comment #7
wim leersThat's exactly what I think is happening. To be fair, it is confusing:
This comment applies to the ENTIRE regexp. Note this is indented less than what follows:
All thee rules together comply with what the spec says:
So AFAICT this is correct. But if we can clarify the comments/code, then great. OTOH, I think there's little value in doing so for something like this, precisely because it's the codifying of a spec, and comparing the code with the spec should always lead to readers ending up concluding it is correct. Hence, agreed with priority.
Comment #8
gabesulliceComment #9
gabesulliceComment #10
gabesullice