From 0ef9b8e0273055fabe4a4665ca9bdee509ee4202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Lang=C3=B3?= Date: Tue, 18 Jul 2017 15:42:33 +0200 Subject: [PATCH] Fix RegExp character class compilation on unicode ranges. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com --- jerry-core/parser/regexp/re-parser.c | 18 ++++++++++++++---- tests/jerry/regexp-character-class.js | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/jerry-core/parser/regexp/re-parser.c b/jerry-core/parser/regexp/re-parser.c index d510c6364..8e028e7d5 100644 --- a/jerry-core/parser/regexp/re-parser.c +++ b/jerry-core/parser/regexp/re-parser.c @@ -419,8 +419,13 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */ } parser_ctx_p->input_curr_p += 2; - append_char_class (re_ctx_p, code_unit, code_unit); - ch = LIT_CHAR_UNDEF; + if (is_range == false && lit_utf8_peek_next (parser_ctx_p->input_curr_p) == LIT_CHAR_MINUS) + { + start = code_unit; + continue; + } + + ch = code_unit; } else if (ch == LIT_CHAR_LOWERCASE_U) { @@ -432,8 +437,13 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */ } parser_ctx_p->input_curr_p += 4; - append_char_class (re_ctx_p, code_unit, code_unit); - ch = LIT_CHAR_UNDEF; + if (is_range == false && lit_utf8_peek_next (parser_ctx_p->input_curr_p) == LIT_CHAR_MINUS) + { + start = code_unit; + continue; + } + + ch = code_unit; } else if (ch == LIT_CHAR_LOWERCASE_D) { diff --git a/tests/jerry/regexp-character-class.js b/tests/jerry/regexp-character-class.js index 83e8d6c95..baa897a30 100644 --- a/tests/jerry/regexp-character-class.js +++ b/tests/jerry/regexp-character-class.js @@ -111,3 +111,21 @@ catch (e) { assert (e instanceof SyntaxError); } + +r = new RegExp ("^[\\u0061-\\u007a]+$").exec("abcdefghjklmnopqrstuvwxyz"); +assert (r == "abcdefghjklmnopqrstuvwxyz"); + +r = new RegExp ("^[\\u0061-\\u007a]+").exec("abcdefghjklmnopqrstuvwxyz"); +assert (r == "abcdefghjklmnopqrstuvwxyz"); + +r = new RegExp ("[\\u0061-\\u007a]+$").exec("abcdefghjklmnopqrstuvwxyz"); +assert (r == "abcdefghjklmnopqrstuvwxyz"); + +r = new RegExp ("^[\\x61-\\x7a]+$").exec("abcdefghjklmnopqrstuvwxyz"); +assert (r == "abcdefghjklmnopqrstuvwxyz"); + +r = new RegExp ("^[\\x61-\\x7a]+").exec("abcdefghjklmnopqrstuvwxyz"); +assert (r == "abcdefghjklmnopqrstuvwxyz"); + +r = new RegExp ("[\\x61-\\x7a]+$").exec("abcdefghjklmnopqrstuvwxyz"); +assert (r == "abcdefghjklmnopqrstuvwxyz");