Fix invalid control escapes during RegExp parsing.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com
This commit is contained in:
Dániel Bátyai
2015-08-10 11:00:48 +02:00
parent c4b1f02947
commit d2ac7c320d
2 changed files with 47 additions and 21 deletions
+32 -21
View File
@@ -265,7 +265,7 @@ re_count_num_of_groups (re_parser_ctx_t *parser_ctx_p) /**< RegExp parser contex
} }
case LIT_CHAR_RIGHT_SQUARE: case LIT_CHAR_RIGHT_SQUARE:
{ {
if (!char_class_in) if (char_class_in)
{ {
char_class_in--; char_class_in--;
} }
@@ -378,18 +378,22 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
} }
else if (ch == LIT_CHAR_LOWERCASE_C) else if (ch == LIT_CHAR_LOWERCASE_C)
{ {
if (lit_utf8_iterator_is_eos (iter_p)) if (!lit_utf8_iterator_is_eos (iter_p))
{ {
return ecma_raise_syntax_error ("invalid character class, end of string after '\\c'"); ch = lit_utf8_iterator_peek_next (iter_p);
}
ch = lit_utf8_iterator_read_next (iter_p); if ((ch >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END)
|| (ch >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END)
if ((ch >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END) || (ch >= LIT_CHAR_0 && ch <= LIT_CHAR_9))
|| (ch >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END)) {
{ /* See ECMA-262 v5, 15.10.2.10 (Point 3) */
/* See ECMA-262 v5, 15.10.2.10 (Point 3) */ ch = (ch % 32);
ch = (ch % 32); lit_utf8_iterator_incr (iter_p);
}
else
{
ch = LIT_CHAR_LOWERCASE_C;
}
} }
} }
else if (ch == LIT_CHAR_LOWERCASE_X) else if (ch == LIT_CHAR_LOWERCASE_X)
@@ -627,19 +631,26 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
} }
else if (ch == LIT_CHAR_LOWERCASE_C) else if (ch == LIT_CHAR_LOWERCASE_C)
{ {
if (lit_utf8_iterator_is_eos (iter_p)) if (!lit_utf8_iterator_is_eos (iter_p))
{ {
out_token_p->value = ch; ch = lit_utf8_iterator_peek_next (iter_p);
break;
if ((ch >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END)
|| (ch >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END))
{
out_token_p->value = (ch % 32);
lit_utf8_iterator_incr (iter_p);
}
else
{
out_token_p->value = LIT_CHAR_BACKSLASH;
lit_utf8_iterator_decr (iter_p);
}
} }
else
ch = lit_utf8_iterator_peek_next (iter_p);
if ((ch >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END)
|| (ch >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END))
{ {
out_token_p->value = (ch % 32); out_token_p->value = LIT_CHAR_BACKSLASH;
lit_utf8_iterator_advance (iter_p, 1); lit_utf8_iterator_decr (iter_p);
} }
} }
else if (ch == LIT_CHAR_LOWERCASE_X else if (ch == LIT_CHAR_LOWERCASE_X
@@ -74,3 +74,18 @@ assert (/([abc]+)\40([d-f]+)\12\1/.exec("abc def\nabc") == "abc def\nabc,abc,def
var expected = "8765432911,8,7,6,5,4,3,2,9,1"; var expected = "8765432911,8,7,6,5,4,3,2,9,1";
assert (/(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)\9(\d)\9/.exec("8765432911") == expected); assert (/(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)\9(\d)\9/.exec("8765432911") == expected);
r = /\c/;
assert (r.exec ("\\c") == "\\c");
r = /[\c]/;
assert (r.exec ("c") == "c");
r = /[\c1]/;
assert (r.exec ("\u0011") == "\u0011");
r = /\c3/;
assert (r.exec ("\\c3") == "\\c3");
r = /\cIasd/;
assert (r.exec ("\tasd") == "\tasd");