diff options
author | Kevin Newton <[email protected]> | 2023-08-03 15:49:29 -0400 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-08-16 17:47:32 -0700 |
commit | 5e9397279bbadb7d5cb08298e23e9fa76198b90e (patch) | |
tree | cbf2e310ce0d2eecaf1f1b0f7edbe6d151dba75a /yarp/regexp.c | |
parent | 72571453204a0e91e474233b619183be8834edba (diff) |
[ruby/yarp] Handle escaping in regexp slow path
https://github.com/ruby/yarp/commit/8dd0a1b281
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8226
Diffstat (limited to 'yarp/regexp.c')
-rw-r--r-- | yarp/regexp.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/yarp/regexp.c b/yarp/regexp.c index ce148c82f2..4d6b67ebe6 100644 --- a/yarp/regexp.c +++ b/yarp/regexp.c @@ -380,11 +380,13 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) { switch (*parser->cursor) { case '#': { // inline comments if (parser->encoding_changed && parser->encoding->multibyte) { + bool escaped = false; + // Here we're going to take a slow path and iterate through // each multibyte character to find the close paren. We do // this because \ can be a trailing byte in some encodings. while (parser->cursor < parser->end) { - if (*parser->cursor == ')') { + if (!escaped && *parser->cursor == ')') { parser->cursor++; return true; } @@ -392,6 +394,7 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) { size_t width = parser->encoding->char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor)); if (width == 0) return false; + escaped = (width == 1) && (*parser->cursor == '\\'); parser->cursor += width; } |