From f226bc20f6df09eb2b988562b4ac9fdc6958c8b0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 27 Dec 2024 09:01:08 +0900 Subject: [PATCH] [Bug #20986] [Prism] Allow escaped multibyte character --- prism/prism.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prism/prism.c b/prism/prism.c index 04c9ca4ac16018..eca276a3571994 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -9618,10 +9618,15 @@ escape_write_escape_encoded(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_ if (width == 1) { escape_write_byte(parser, buffer, regular_expression_buffer, flags, escape_byte(*parser->current.end++, flags)); + } else if (width > 1) { + // Valid multibyte character. Just ignore escape. + pm_buffer_t *b = (flags & PM_ESCAPE_FLAG_REGEXP) ? regular_expression_buffer : buffer; + pm_buffer_append_bytes(b, parser->current.end, width); + parser->current.end += width; } else { // Assume the next character wasn't meant to be part of this escape // sequence since it is invalid. Add an error and move on. - parser->current.end += width; + parser->current.end++; pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_CONTROL); } }