-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[JsonPath] Improve escape sequence validation in name selector #60802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.3
Are you sure you want to change the base?
[JsonPath] Improve escape sequence validation in name selector #60802
Conversation
alexandre-daubois
commented
Jun 16, 2025
Q | A |
---|---|
Branch? | 7.3 |
Bug fix? | yes |
New feature? | no |
Deprecations? | no |
Issues | - |
License | MIT |
'b' => "\b", | ||
'f' => "\f", | ||
'b' => "\x08", | ||
'f' => "\x0C", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why changing those ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\f
is a mistake, but \b
is actually not recognized by PHP, thus using the hex value directly
03d86c3
to
fe04be1
Compare
fe04be1
to
531a978
Compare
@@ -227,4 +233,24 @@ public static function parseCommaSeparatedValues(string $expr): array | |||
|
|||
return $parts; | |||
} | |||
|
|||
private static function validateEscapeSequences(string $str, string $quoteChar): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to merge the new loop with the existing one? can we do everything in one pass?
} | ||
|
||
if (!\in_array($next = $str[$i + 1], [$quoteChar, '\\', '/', 'b', 'f', 'n', 'r', 't', 'u'], true)) { | ||
throw new JsonCrawlerException('', \sprintf('Invalid escape sequence "\\%s" in %s-quoted string', $next, "'" === $quoteChar ? 'single' : 'double')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite sure this case could be detected during the unescaping loop, as this exception corresponds to the default => $char.$str[$i + 1], // keep the backslash
branch in the match, which could become a throwing branch.
} | ||
|
||
if ('u' === $next && (!isset($str[$i + 5]) || !ctype_xdigit(substr($str, $i + 2, 4)))) { | ||
throw new JsonCrawlerException('', 'Invalid unicode escape sequence'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unescapeUnicodeSequence
could be responsible for this validation instead of treating invalid sequences as literal (which would become dead code if we validate in a previous loop)