diff --git a/libregexp.c b/libregexp.c index c2f9a1f..64213fc 100644 --- a/libregexp.c +++ b/libregexp.c @@ -783,6 +783,9 @@ static int get_class_atom(REParseState *s, CharRange *cr, /* always valid to escape these characters */ goto normal_char; } else if (s->is_unicode) { + // special case: allowed inside [] but not outside + if (ret == -2 && *p == '-' && inclass) + goto normal_char; invalid_escape: return re_parse_error(s, "invalid escape sequence in regular expression"); } else { diff --git a/tests/test_builtin.js b/tests/test_builtin.js index 93e2490..2428c69 100644 --- a/tests/test_builtin.js +++ b/tests/test_builtin.js @@ -699,6 +699,9 @@ function test_regexp() ex = _ex; } assert(ex?.message, "invalid class range"); + + eval("/[\\-]/"); + eval("/[\\-]/u"); } function test_symbol()