Skip to content

Commit

Permalink
Fixed template literal parsing
Browse files Browse the repository at this point in the history
Fixed an unhandled corner case while parsing slashes and template literals.
This patch fixes #2039 and adds a test case for it.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
  • Loading branch information
rerobika authored and yichoi committed Nov 9, 2017
1 parent c3a9821 commit 519ba8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 10 additions & 8 deletions jerry-core/parser/js/js-lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,16 @@ lexer_parse_string (parser_context_t *context_p) /**< context */
continue;
}
}
#ifndef CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
else if (str_end_character == LIT_CHAR_GRAVE_ACCENT &&
source_p[0] == LIT_CHAR_DOLLAR_SIGN &&
source_p + 1 < source_end_p &&
source_p[1] == LIT_CHAR_LEFT_BRACE)
{
source_p++;
break;
}
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */

if (*source_p >= LEXER_UTF8_4BYTE_START)
{
Expand All @@ -737,14 +747,6 @@ lexer_parse_string (parser_context_t *context_p) /**< context */
#ifndef CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
else if (str_end_character == LIT_CHAR_GRAVE_ACCENT)
{
if (source_p[0] == LIT_CHAR_LEFT_BRACE
&& source_p[-1] == LIT_CHAR_DOLLAR_SIGN
&& source_p[-2] != LIT_CHAR_BACKSLASH)
{
length--;
break;
}

/* Newline (without backslash) is part of the string. */
if (*source_p == LIT_CHAR_CR)
{
Expand Down
15 changes: 15 additions & 0 deletions tests/jerry/fail/regression-test-issue-2039.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

` ?N\7$D\\${D ?N@ ${Z ?11.1Z7$D\\${D ?N@ ${Z ?11.1 ?11.1.G.{Z %11.0.G.

0 comments on commit 519ba8e

Please sign in to comment.