fix: disallow \8, \9 in strict mode string (#11852)
This commit is contained in:
parent
3680f019d7
commit
2bf38fb914
@ -139,6 +139,7 @@ export const ErrorMessages = Object.freeze({
|
|||||||
StrictEvalArgumentsBinding: "Binding '%0' in strict mode",
|
StrictEvalArgumentsBinding: "Binding '%0' in strict mode",
|
||||||
StrictFunction:
|
StrictFunction:
|
||||||
"In strict mode code, functions can only be declared at top level or inside a block",
|
"In strict mode code, functions can only be declared at top level or inside a block",
|
||||||
|
StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'",
|
||||||
StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode",
|
StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode",
|
||||||
StrictWith: "'with' in strict mode",
|
StrictWith: "'with' in strict mode",
|
||||||
SuperNotAllowed:
|
SuperNotAllowed:
|
||||||
|
|||||||
@ -1357,6 +1357,8 @@ export default class Tokenizer extends ParserErrors {
|
|||||||
case charCodes.digit9:
|
case charCodes.digit9:
|
||||||
if (inTemplate) {
|
if (inTemplate) {
|
||||||
return null;
|
return null;
|
||||||
|
} else if (this.state.strict) {
|
||||||
|
this.raise(this.state.pos - 1, Errors.StrictNumericEscape);
|
||||||
}
|
}
|
||||||
// fall through
|
// fall through
|
||||||
default:
|
default:
|
||||||
@ -1385,7 +1387,7 @@ export default class Tokenizer extends ParserErrors {
|
|||||||
if (inTemplate) {
|
if (inTemplate) {
|
||||||
return null;
|
return null;
|
||||||
} else if (this.state.strict) {
|
} else if (this.state.strict) {
|
||||||
this.raise(codePos, Errors.StrictOctalLiteral);
|
this.raise(codePos, Errors.StrictNumericEscape);
|
||||||
} else {
|
} else {
|
||||||
// This property is used to throw an error for
|
// This property is used to throw an error for
|
||||||
// an octal literal in a directive that occurs prior
|
// an octal literal in a directive that occurs prior
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (2:4)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (2:4)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (7:4)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (7:4)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (8:4)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (8:4)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:4)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:4)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (19:4)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (19:4)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (20:4)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (20:4)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (25:2)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (25:2)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (30:2)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (30:2)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (31:2)"
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (31:2)"
|
||||||
@ -2,13 +2,13 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":96,"loc":{"start":{"line":1,"column":0},"end":{"line":14,"column":22}},
|
"start":0,"end":96,"loc":{"start":{"line":1,"column":0},"end":{"line":14,"column":22}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (8:2)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (8:2)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (9:2)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (9:2)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (11:0)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (11:0)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (12:0)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (12:0)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:2)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:2)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:10)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:10)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:18)",
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (14:18)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:2)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:2)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:10)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:10)",
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:18)",
|
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:18)",
|
||||||
5
packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/input.js
vendored
Normal file
5
packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/input.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
"\8","\9";
|
||||||
|
() => {
|
||||||
|
"use strict";
|
||||||
|
"\8", "\9";
|
||||||
|
}
|
||||||
106
packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/output.json
vendored
Normal file
106
packages/babel-parser/test/fixtures/core/escape-string/non-octal-eight-and-nine/output.json
vendored
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||||
|
"errors": [
|
||||||
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:4)",
|
||||||
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (4:10)"
|
||||||
|
],
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||||
|
"sourceType": "script",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
|
||||||
|
"expression": {
|
||||||
|
"type": "SequenceExpression",
|
||||||
|
"start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}},
|
||||||
|
"expressions": [
|
||||||
|
{
|
||||||
|
"type": "StringLiteral",
|
||||||
|
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": "8",
|
||||||
|
"raw": "\"\\8\""
|
||||||
|
},
|
||||||
|
"value": "8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "StringLiteral",
|
||||||
|
"start":5,"end":9,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":9}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": "9",
|
||||||
|
"raw": "\"\\9\""
|
||||||
|
},
|
||||||
|
"value": "9"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":11,"end":50,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":1}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":11,"end":50,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":1}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"type": "BlockStatement",
|
||||||
|
"start":17,"end":50,"loc":{"start":{"line":2,"column":6},"end":{"line":5,"column":1}},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":37,"end":48,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":13}},
|
||||||
|
"expression": {
|
||||||
|
"type": "SequenceExpression",
|
||||||
|
"start":37,"end":47,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":12}},
|
||||||
|
"expressions": [
|
||||||
|
{
|
||||||
|
"type": "StringLiteral",
|
||||||
|
"start":37,"end":41,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":6}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": "8",
|
||||||
|
"raw": "\"\\8\""
|
||||||
|
},
|
||||||
|
"value": "8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "StringLiteral",
|
||||||
|
"start":43,"end":47,"loc":{"start":{"line":4,"column":8},"end":{"line":4,"column":12}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": "9",
|
||||||
|
"raw": "\"\\9\""
|
||||||
|
},
|
||||||
|
"value": "9"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": [
|
||||||
|
{
|
||||||
|
"type": "Directive",
|
||||||
|
"start":21,"end":34,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":15}},
|
||||||
|
"value": {
|
||||||
|
"type": "DirectiveLiteral",
|
||||||
|
"start":21,"end":33,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":14}},
|
||||||
|
"value": "use strict",
|
||||||
|
"extra": {
|
||||||
|
"raw": "\"use strict\"",
|
||||||
|
"rawValue": "use strict"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":76}},
|
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":76}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:69)"
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:69)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":50}},
|
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":50}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:38)"
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:38)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:35)"
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:35)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:35)"
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:35)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":50}},
|
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":50}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:38)"
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:38)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":76}},
|
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":76}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:69)"
|
"SyntaxError: The only valid numeric escape in strict mode is '\\0' (1:69)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user