Legacy octal escapes should not be allowed in template strings (#4227)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai 2020-09-25 10:14:28 +02:00 committed by GitHub
parent 43e03a1ac6
commit 629a0e51c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View File

@ -1083,6 +1083,13 @@ lexer_parse_string (parser_context_t *context_p, /**< context */
* converted to a character which has the same byte length. */
if (*source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_3)
{
#if ENABLED (JERRY_ESNEXT)
if (str_end_character == LIT_CHAR_GRAVE_ACCENT)
{
parser_raise_error (context_p, PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE);
}
#endif
if (context_p->status_flags & PARSER_IS_STRICT)
{
parser_raise_error (context_p, PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED);

View File

@ -1003,6 +1003,12 @@ parser_error_to_string (parser_error_t error) /**< error code */
{
return "Octal escape sequences are not allowed in strict mode.";
}
#if ENABLED (JERRY_ESNEXT)
case PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE:
{
return "Octal escape sequences are not allowed in template strings.";
}
#endif /* ENABLED (JERRY_ESNEXT) */
case PARSER_ERR_STRICT_IDENT_NOT_ALLOWED:
{
return "Identifier name is reserved in strict mode.";

View File

@ -77,6 +77,9 @@ typedef enum
PARSER_ERR_NEWLINE_NOT_ALLOWED, /**< newline is not allowed */
PARSER_ERR_OCTAL_NUMBER_NOT_ALLOWED, /**< octal numbers are not allowed in strict mode */
PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED, /**< octal escape sequences are not allowed in strict mode */
#if ENABLED (JERRY_ESNEXT)
PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE, /**< octal escape sequences are not allowed in template strings */
#endif /* ENABLED (JERRY_ESNEXT) */
PARSER_ERR_STRICT_IDENT_NOT_ALLOWED, /**< identifier name is reserved in strict mode */
PARSER_ERR_EVAL_NOT_ALLOWED, /**< eval is not allowed here in strict mode */
PARSER_ERR_ARGUMENTS_NOT_ALLOWED, /**< arguments is not allowed here in strict mode */

View File

@ -311,7 +311,6 @@
<test id="language/expressions/tagged-template/cache-identical-source-eval.js"><reason></reason></test>
<test id="language/expressions/tagged-template/cache-identical-source.js"><reason></reason></test>
<test id="language/expressions/tagged-template/cache-identical-source-new-function.js"><reason></reason></test>
<test id="language/expressions/template-literal/invalid-legacy-octal-escape-sequence.js"><reason></reason></test>
<test id="language/line-terminators/S7.3_A2.3.js"><reason>No longer a SyntaxError in ES11</reason></test>
<test id="language/line-terminators/S7.3_A2.4.js"><reason>No longer a SyntaxError in ES11</reason></test>
<test id="language/literals/string/7.8.4-1-s.js"><reason></reason></test>

View File

@ -3789,7 +3789,6 @@
<test id="language/expressions/super/realm.js"><reason></reason></test>
<test id="language/expressions/tagged-template/cache-realm.js"><reason></reason></test>
<test id="language/expressions/tagged-template/invalid-escape-sequences.js"><reason></reason></test>
<test id="language/expressions/template-literal/invalid-legacy-octal-escape-sequence.js"><reason></reason></test>
<test id="language/expressions/typeof/proxy.js"><reason></reason></test>
<test id="language/expressions/yield/star-return-is-null.js"><reason></reason></test>
<test id="language/expressions/yield/star-throw-is-null.js"><reason></reason></test>