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 1 commit
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 |
---|---|---|
|
@@ -897,6 +897,19 @@ export default class Tokenizer extends LocationParser { | |
|
||
let total = 0; | ||
|
||
// Called from readHexChar | ||
if (radix === 16) { | ||
const unicode = this.input.slice(this.state.pos, this.state.pos + len); | ||
|
||
if (unicode.includes("_")) { | ||
const numSeparatorPos = this.input.indexOf("_"); | ||
this.raise( | ||
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. I don't think we should throw an error like this if user does not enable 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. You're right. |
||
numSeparatorPos, | ||
"Numeric separators are not allowed inside unicode escape sequences", | ||
); | ||
} | ||
} | ||
|
||
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { | ||
const code = this.input.charCodeAt(this.state.pos); | ||
let val; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"\x1_2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "throws": "Numeric separators are not allowed inside unicode escape sequences (1:4)" } |
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)" } |
Large diffs are not rendered by default.
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.
Other than
readCodePoint
,readHexChar
could also be called fromreadRadixNumber
. Did you checked whether0xf_f
can be successfully parsed?We could add an extra
allowNumSeparator: boolean
toreadHexChar
and set
allowNumSeparator = true
when calling fromreadCodePoint
.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.
Good idea.