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
Remove length restriction from JSX entities, and ignore Object.prototype
#14327
Changes from all commits
7c4fb2f
767d5c7
26d232a
d690316
de37f2b
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 |
---|---|---|
|
@@ -1174,7 +1174,7 @@ export default class Tokenizer extends ParserErrors { | |
radix: number, | ||
len?: number, | ||
forceLen?: boolean, | ||
allowNumSeparator: boolean = true, | ||
allowNumSeparator: boolean | "bail" = true, | ||
): number | null { | ||
const start = this.state.pos; | ||
const forbiddenSiblings = | ||
|
@@ -1197,7 +1197,7 @@ export default class Tokenizer extends ParserErrors { | |
const code = this.input.charCodeAt(this.state.pos); | ||
let val; | ||
|
||
if (code === charCodes.underscore) { | ||
if (code === charCodes.underscore && allowNumSeparator !== "bail") { | ||
const prev = this.input.charCodeAt(this.state.pos - 1); | ||
const next = this.input.charCodeAt(this.state.pos + 1); | ||
if (allowedSiblings.indexOf(next) === -1) { | ||
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. Not related to this PR: these errors should be thrown only when 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'll open a PR when this is merged. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<a> | ||
Ӓ | ||
઼ | ||
Ӓ | ||
઼ | ||
� | ||
</a> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":112,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":112}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":112,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":112}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":112,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":112}}, | ||
"expression": { | ||
"type": "JSXElement", | ||
"start":0,"end":112,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":112}}, | ||
"openingElement": { | ||
"type": "JSXOpeningElement", | ||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":3,"index":3}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2}}, | ||
"name": "a" | ||
}, | ||
"attributes": [], | ||
"selfClosing": false | ||
}, | ||
"closingElement": { | ||
"type": "JSXClosingElement", | ||
"start":108,"end":112,"loc":{"start":{"line":7,"column":0,"index":108},"end":{"line":7,"column":4,"index":112}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":110,"end":111,"loc":{"start":{"line":7,"column":2,"index":110},"end":{"line":7,"column":3,"index":111}}, | ||
"name": "a" | ||
} | ||
}, | ||
"children": [ | ||
{ | ||
"type": "JSXText", | ||
"start":3,"end":108,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":7,"column":0,"index":108}}, | ||
"extra": { | ||
"rawValue": "\n Ӓ\n ઼\n Ӓ\n ઼\n \u0000\n", | ||
"raw": "\n Ӓ\n ઼\n Ӓ\n ઼\n �\n" | ||
}, | ||
"value": "\n Ӓ\n ઼\n Ӓ\n ઼\n \u0000\n" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a>&</a> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"expression": { | ||
"type": "JSXElement", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"openingElement": { | ||
"type": "JSXOpeningElement", | ||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":3,"index":3}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2}}, | ||
"name": "a" | ||
}, | ||
"attributes": [], | ||
"selfClosing": false | ||
}, | ||
"closingElement": { | ||
"type": "JSXClosingElement", | ||
"start":8,"end":12,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":12,"index":12}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11}}, | ||
"name": "a" | ||
} | ||
}, | ||
"children": [ | ||
{ | ||
"type": "JSXText", | ||
"start":3,"end":8,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":8,"index":8}}, | ||
"extra": { | ||
"rawValue": "&", | ||
"raw": "&" | ||
}, | ||
"value": "&" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<a> | ||
& | ||
&a; | ||
& ; | ||
&xamp; | ||
�_0; | ||
</a> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":61,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":61}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":61,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":61}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":61,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":61}}, | ||
"expression": { | ||
"type": "JSXElement", | ||
"start":0,"end":61,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":7,"column":4,"index":61}}, | ||
"openingElement": { | ||
"type": "JSXOpeningElement", | ||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":3,"index":3}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2}}, | ||
"name": "a" | ||
}, | ||
"attributes": [], | ||
"selfClosing": false | ||
}, | ||
"closingElement": { | ||
"type": "JSXClosingElement", | ||
"start":57,"end":61,"loc":{"start":{"line":7,"column":0,"index":57},"end":{"line":7,"column":4,"index":61}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":59,"end":60,"loc":{"start":{"line":7,"column":2,"index":59},"end":{"line":7,"column":3,"index":60}}, | ||
"name": "a" | ||
} | ||
}, | ||
"children": [ | ||
{ | ||
"type": "JSXText", | ||
"start":3,"end":57,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":7,"column":0,"index":57}}, | ||
"extra": { | ||
"rawValue": "\n &\n &a;\n & ;\n &xamp;\n �_0;\n", | ||
"raw": "\n &\n &a;\n & ;\n &xamp;\n �_0;\n" | ||
}, | ||
"value": "\n &\n &a;\n & ;\n &xamp;\n �_0;\n" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a>&valueOf;</a> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"expression": { | ||
"type": "JSXElement", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"openingElement": { | ||
"type": "JSXOpeningElement", | ||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":3,"index":3}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2}}, | ||
"name": "a" | ||
}, | ||
"attributes": [], | ||
"selfClosing": false | ||
}, | ||
"closingElement": { | ||
"type": "JSXClosingElement", | ||
"start":12,"end":16,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":16,"index":16}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":14,"end":15,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":15,"index":15}}, | ||
"name": "a" | ||
} | ||
}, | ||
"children": [ | ||
{ | ||
"type": "JSXText", | ||
"start":3,"end":12,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":12,"index":12}}, | ||
"extra": { | ||
"rawValue": "&valueOf;", | ||
"raw": "&valueOf;" | ||
}, | ||
"value": "&valueOf;" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
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.
The invalid JSX syntax
�_0;
is recoverable: we can either passallowNumSeparator: false
and refine the error message ofNumericSeparatorInEscapeSequence
, or pass a context string so we can throw different errors. Though personally I think html entities are just like escape sequences in JS.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.
It's not invalid, it's rendeded as-is and not as an HTML entity. I'll add a test.