Skip to content

Commit

Permalink
Ensure Unicode escapes can't be used in character classes yet
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Jun 22, 2022
1 parent 72d308c commit 879eb7a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 40 deletions.
112 changes: 75 additions & 37 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ IdentifierStart
/ "$"
/ "_"
/ "\\" @UnicodeEscapeSequence
/ "\\" @ExtendedUnicodeEscapeSequence

IdentifierPart
= IdentifierStart
Expand Down Expand Up @@ -329,12 +330,12 @@ StringLiteral "string"

DoubleStringCharacter
= $(!('"' / "\\" / LineTerminator) SourceCharacter)
/ "\\" @EscapeSequence
/ "\\" @ExtendedEscapeSequence
/ LineContinuation

SingleStringCharacter
= $(!("'" / "\\" / LineTerminator) SourceCharacter)
/ "\\" @EscapeSequence
/ "\\" @ExtendedEscapeSequence
/ LineContinuation

CharacterClassMatcher "character class"
Expand Down Expand Up @@ -372,6 +373,10 @@ ClassCharacter
LineContinuation
= "\\" LineTerminatorSequence { return ""; }

ExtendedEscapeSequence
= EscapeSequence
/ ExtendedUnicodeEscapeSequence

EscapeSequence
= CharacterEscapeSequence
/ "0" !DecimalDigit { return "\0"; }
Expand Down Expand Up @@ -411,7 +416,9 @@ UnicodeEscapeSequence
= "u" digits:$(HexDigit HexDigit HexDigit HexDigit) {
return String.fromCharCode(parseInt(digits, 16));
}
/ "u{" digits:$HexDigit+ "}" {

ExtendedUnicodeEscapeSequence
= "u{" digits:$HexDigit+ "}" {
// String.fromCodePoint() is not supported in IE11.
let codepoint = parseInt(digits, 16);
if (codepoint > 0x10FFFF) {
Expand Down

0 comments on commit 879eb7a

Please sign in to comment.