Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Accept /[\-]/u as a valid regular expression #288

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libregexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions tests/test_builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ function test_regexp()
ex = _ex;
}
assert(ex?.message, "invalid class range");

eval("/[\\-]/");
eval("/[\\-]/u");
}

function test_symbol()
Expand Down
Loading