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
[parser] Disallow numeric separator in unicode scape sequences #10468
Changes from 4 commits
8d5ed90
1798998
b25c675
c52747a
c996c1c
b256ee5
9549cf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -880,7 +880,11 @@ export default class Tokenizer extends LocationParser { | |||||
// were read, the integer value otherwise. When `len` is given, this | ||||||
// will return `null` unless the integer has exactly `len` digits. | ||||||
|
||||||
readInt(radix: number, len?: number): number | null { | ||||||
readInt( | ||||||
radix: number, | ||||||
len?: number, | ||||||
allowNumSeparator: boolean = false, | ||||||
): number | null { | ||||||
const start = this.state.pos; | ||||||
const forbiddenSiblings = | ||||||
radix === 16 | ||||||
|
@@ -917,6 +921,13 @@ export default class Tokenizer extends LocationParser { | |||||
this.raise(this.state.pos, "Invalid or unexpected token"); | ||||||
} | ||||||
|
||||||
if (allowNumSeparator) { | ||||||
this.raise( | ||||||
this.state.pos, | ||||||
"Numeric separators are not allowed inside unicode escape sequences", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Numeric separators are also not allowed in hex escape sequences: var c = \x1_0
Suggested change
Could you also add a test case on hex escape sequences? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||||||
); | ||||||
} | ||||||
|
||||||
// Ignore this _ character | ||||||
++this.state.pos; | ||||||
continue; | ||||||
|
@@ -1058,6 +1069,7 @@ export default class Tokenizer extends LocationParser { | |||||
code = this.readHexChar( | ||||||
this.input.indexOf("}", this.state.pos) - this.state.pos, | ||||||
throwOnInvalid, | ||||||
true, | ||||||
); | ||||||
++this.state.pos; | ||||||
if (code === null) { | ||||||
|
@@ -1072,7 +1084,7 @@ export default class Tokenizer extends LocationParser { | |||||
} | ||||||
} | ||||||
} else { | ||||||
code = this.readHexChar(4, throwOnInvalid); | ||||||
code = this.readHexChar(4, throwOnInvalid, true); | ||||||
} | ||||||
return code; | ||||||
} | ||||||
|
@@ -1250,9 +1262,13 @@ export default class Tokenizer extends LocationParser { | |||||
|
||||||
// Used to read character escape sequences ('\x', '\u'). | ||||||
|
||||||
readHexChar(len: number, throwOnInvalid: boolean): number | null { | ||||||
readHexChar( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Good catch. So, now it is exposed to |
||||||
len: number, | ||||||
throwOnInvalid: boolean, | ||||||
allowNumSeparator: boolean = false, | ||||||
): number | null { | ||||||
const codePos = this.state.pos; | ||||||
const n = this.readInt(16, len); | ||||||
const n = this.readInt(16, len, allowNumSeparator); | ||||||
if (n === null) { | ||||||
if (throwOnInvalid) { | ||||||
this.raise(codePos, "Bad character escape sequence"); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"\u12_34" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "throws": "Numeric separators are not allowed inside unicode escape sequences (1:5)" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"\u{1F_639}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "throws": "Numeric separators are not allowed inside unicode escape sequences (1:6)" } |
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.
Shouldn't it only throw if it is not allowed?
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.
Oh... My bad. I'll fix it right now.