diff --git a/lib/PhpParser/Node/Scalar/String_.php b/lib/PhpParser/Node/Scalar/String_.php index 9c7bef2947..f284e980e0 100644 --- a/lib/PhpParser/Node/Scalar/String_.php +++ b/lib/PhpParser/Node/Scalar/String_.php @@ -116,7 +116,7 @@ public static function parseEscapeSequences(string $str, ?string $quote, bool $p $extra = ''; if ($parseUnicodeEscape) { - $extra = '|u\{([0-9a-fA-F]+)\}'; + $extra = '|u\{([0-9a-fA-F]+)\}|u\{'; } return preg_replace_callback( @@ -131,6 +131,9 @@ function ($matches) { return chr(hexdec(substr($str, 1))); } if ('u' === $str[0]) { + if (!isset($matches[2])) { + throw new Error('Invalid UTF-8 codepoint escape sequence'); + } // PHP 8.6 warns when hexdec() produces a float. $dec = @hexdec($matches[2]); // If it overflowed to float, treat as INT_MAX, it will throw an error anyway. diff --git a/test/code/parser/scalar/unicodeEscape.test b/test/code/parser/scalar/unicodeEscape.test index c672fb08f0..140fa89f73 100644 --- a/test/code/parser/scalar/unicodeEscape.test +++ b/test/code/parser/scalar/unicodeEscape.test @@ -86,3 +86,35 @@ Invalid UTF-8 codepoint escape sequence: Codepoint too large on line 2 "\u{110000}"; ----- Invalid UTF-8 codepoint escape sequence: Codepoint too large on line 2 +----- +