Skip to content

Commit 8dd0a1b

Browse files
committed
Handle escaping in regexp slow path
1 parent cd16f67 commit 8dd0a1b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/regexp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,18 +380,21 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) {
380380
switch (*parser->cursor) {
381381
case '#': { // inline comments
382382
if (parser->encoding_changed && parser->encoding->multibyte) {
383+
bool escaped = false;
384+
383385
// Here we're going to take a slow path and iterate through
384386
// each multibyte character to find the close paren. We do
385387
// this because \ can be a trailing byte in some encodings.
386388
while (parser->cursor < parser->end) {
387-
if (*parser->cursor == ')') {
389+
if (!escaped && *parser->cursor == ')') {
388390
parser->cursor++;
389391
return true;
390392
}
391393

392394
size_t width = parser->encoding->char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
393395
if (width == 0) return false;
394396

397+
escaped = (width == 1) && (*parser->cursor == '\\');
395398
parser->cursor += width;
396399
}
397400

0 commit comments

Comments
 (0)