Skip to content

Commit 7619421

Browse files
committed
Accept /[\-]/u as a valid regular expression
The non-Unicode version of the pattern was already accepted. test262 tests it in an inverted sense in test/built-ins/RegExp/unicode_restricted_identity_escape.js but it appears to be per spec and both V8 and Spidermonkey accept it. Fixes: #286
1 parent 7dd2868 commit 7619421

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

libregexp.c

+3
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ static int get_class_atom(REParseState *s, CharRange *cr,
783783
/* always valid to escape these characters */
784784
goto normal_char;
785785
} else if (s->is_unicode) {
786+
// special case: allowed inside [] but not outside
787+
if (ret == -2 && *p == '-' && inclass)
788+
goto normal_char;
786789
invalid_escape:
787790
return re_parse_error(s, "invalid escape sequence in regular expression");
788791
} else {

tests/test_builtin.js

+3
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ function test_regexp()
699699
ex = _ex;
700700
}
701701
assert(ex?.message, "invalid class range");
702+
703+
eval("/[\\-]/");
704+
eval("/[\\-]/u");
702705
}
703706

704707
function test_symbol()

0 commit comments

Comments
 (0)