Skip to content

Commit 57db5ca

Browse files
committed
Fix regexp character classes with \uNNNN and \xNN code points
Currently, if a regexp contains a character class and that character class contains a hex-specified code point -- either \uNNNN or \xNN --, then the character 'u' or 'x' is added to the character class as well. This patch fixes the error and also adds a regression test covering the issue. Fixes #962 JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 69291e2 commit 57db5ca

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

jerry-core/parser/regexp/re-parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
421421

422422
parser_ctx_p->input_curr_p += 2;
423423
append_char_class (re_ctx_p, code_unit, code_unit);
424+
ch = LIT_CHAR_UNDEF;
424425
}
425426
else if (ch == LIT_CHAR_LOWERCASE_U)
426427
{
@@ -433,6 +434,7 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
433434

434435
parser_ctx_p->input_curr_p += 4;
435436
append_char_class (re_ctx_p, code_unit, code_unit);
437+
ch = LIT_CHAR_UNDEF;
436438
}
437439
else if (ch == LIT_CHAR_LOWERCASE_D)
438440
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2016 Samsung Electronics Co., Ltd.
2+
// Copyright 2016 University of Szeged.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
function re_test (pattern, string, expected)
17+
{
18+
assert ((new RegExp(pattern)).exec(string) == expected);
19+
}
20+
21+
re_test("[\\u0020]", "u", null);
22+
re_test("[\\u0020]", " ", " ");
23+
re_test("[\\u0020]", "x", null);
24+
25+
re_test("[\\x20]", "u", null);
26+
re_test("[\\x20]", " ", " ");
27+
re_test("[\\x20]", "x", null);

0 commit comments

Comments
 (0)