From 629a0e51c4664a91dbbe5eec41bc6642db87b1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20B=C3=A1tyai?= Date: Fri, 25 Sep 2020 10:14:28 +0200 Subject: [PATCH] Legacy octal escapes should not be allowed in template strings (#4227) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu --- jerry-core/parser/js/js-lexer.c | 7 +++++++ jerry-core/parser/js/js-parser-util.c | 6 ++++++ jerry-core/parser/js/js-parser.h | 3 +++ tests/test262-es6-excludelist.xml | 1 - tests/test262-esnext-excludelist.xml | 1 - 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c index efcf9238a..557331a25 100644 --- a/jerry-core/parser/js/js-lexer.c +++ b/jerry-core/parser/js/js-lexer.c @@ -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); diff --git a/jerry-core/parser/js/js-parser-util.c b/jerry-core/parser/js/js-parser-util.c index eea911caf..02b9a0dd7 100644 --- a/jerry-core/parser/js/js-parser-util.c +++ b/jerry-core/parser/js/js-parser-util.c @@ -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."; diff --git a/jerry-core/parser/js/js-parser.h b/jerry-core/parser/js/js-parser.h index ad29469cd..c9a8ec8b0 100644 --- a/jerry-core/parser/js/js-parser.h +++ b/jerry-core/parser/js/js-parser.h @@ -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 */ diff --git a/tests/test262-es6-excludelist.xml b/tests/test262-es6-excludelist.xml index cab7a9572..cc9a56ad4 100644 --- a/tests/test262-es6-excludelist.xml +++ b/tests/test262-es6-excludelist.xml @@ -311,7 +311,6 @@ - No longer a SyntaxError in ES11 No longer a SyntaxError in ES11 diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml index 5d2d8f721..90f51df6f 100644 --- a/tests/test262-esnext-excludelist.xml +++ b/tests/test262-esnext-excludelist.xml @@ -3789,7 +3789,6 @@ -