[ruby/yarp] Handle escaping in regexp slow path
https://github.com/ruby/yarp/commit/8dd0a1b281
This commit is contained in:
parent
7257145320
commit
5e9397279b
Notes:
git
2023-08-17 00:48:04 +00:00
@ -380,11 +380,13 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) {
|
|||||||
switch (*parser->cursor) {
|
switch (*parser->cursor) {
|
||||||
case '#': { // inline comments
|
case '#': { // inline comments
|
||||||
if (parser->encoding_changed && parser->encoding->multibyte) {
|
if (parser->encoding_changed && parser->encoding->multibyte) {
|
||||||
|
bool escaped = false;
|
||||||
|
|
||||||
// Here we're going to take a slow path and iterate through
|
// Here we're going to take a slow path and iterate through
|
||||||
// each multibyte character to find the close paren. We do
|
// each multibyte character to find the close paren. We do
|
||||||
// this because \ can be a trailing byte in some encodings.
|
// this because \ can be a trailing byte in some encodings.
|
||||||
while (parser->cursor < parser->end) {
|
while (parser->cursor < parser->end) {
|
||||||
if (*parser->cursor == ')') {
|
if (!escaped && *parser->cursor == ')') {
|
||||||
parser->cursor++;
|
parser->cursor++;
|
||||||
return true;
|
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));
|
size_t width = parser->encoding->char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
|
||||||
if (width == 0) return false;
|
if (width == 0) return false;
|
||||||
|
|
||||||
|
escaped = (width == 1) && (*parser->cursor == '\\');
|
||||||
parser->cursor += width;
|
parser->cursor += width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user