Allow "<NUL>" character within string literals in strict mode

JerryScript-DCO-1.0-Signed-off-by: Yanhui Shen shen.elf@gmail.com
This commit is contained in:
Yanhui Shen 2017-08-15 10:29:23 +08:00 committed by yichoi
parent 522c7d3f87
commit b32e5444d8
2 changed files with 56 additions and 0 deletions

View File

@ -615,6 +615,16 @@ lexer_parse_string (parser_context_t *context_p) /**< context */
continue;
}
if (*source_p == LIT_CHAR_0
&& source_p + 1 < source_end_p
&& (*(source_p + 1) < LIT_CHAR_0 || *(source_p + 1) > LIT_CHAR_9))
{
source_p++;
column++;
length++;
continue;
}
/* Except \x, \u, and octal numbers, everything is
* converted to a character which has the same byte length. */
if (*source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_3)

View File

@ -70,6 +70,52 @@ try
assert (e instanceof TypeError);
}
try
{
eval ("'\\" + "101'");
assert (false);
} catch (e)
{
assert (e instanceof SyntaxError);
}
try
{
var str1 = "'\\" + "0'";
var str2 = "'\\x" + "00'";
eval (str1);
assert (eval (str1) === eval (str2));
} catch (e)
{
assert (false);
}
try
{
var str1 = "'\\" + "0" + "\\" + "0" + "\\" + "0'";
var str2 = "'\\x" + "00" + "\\x" + "00" + "\\x" + "00'";
eval (str1);
assert (eval (str1) === eval (str2));
} catch (e)
{
assert (false);
}
try
{
var str1 = "'foo\\" + "0" + "bar'";
var str2 = "'foo\\x" + "00" + "bar'";
eval (str1);
assert (eval (str1) === eval (str2));
} catch (e)
{
assert (false);
}
(function (a) {
(function (a) {
});