summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-10-07 10:02:19 -0400
committergit <svn-admin@ruby-lang.org>2024-10-07 14:39:17 +0000
commitfa547b809aba50da72c9145904b5605481fdce3e (patch)
tree2f83f78c3ff1a10e8df464f57ee15db8ba321792
parent216d087f50de719d551592e589f7ecece00570da (diff)
[ruby/prism] Fix up errors on invalid escape character syntax
https://github.com/ruby/prism/commit/14c8559378
-rw-r--r--prism/prism.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 24023525e5..76a1758f38 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -9885,6 +9885,10 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
}
case 'c': {
parser->current.end++;
+ if (flags & PM_ESCAPE_FLAG_CONTROL) {
+ pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT);
+ }
+
if (parser->current.end == parser->end) {
pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_CONTROL);
return;
@@ -9898,10 +9902,6 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
return;
}
case '\\':
- if (flags & PM_ESCAPE_FLAG_CONTROL) {
- pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT);
- return;
- }
parser->current.end++;
if (match(parser, 'u') || match(parser, 'U')) {
@@ -9935,6 +9935,10 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
}
case 'C': {
parser->current.end++;
+ if (flags & PM_ESCAPE_FLAG_CONTROL) {
+ pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT);
+ }
+
if (peek(parser) != '-') {
size_t width = parser->encoding->char_width(parser->current.end, parser->end - parser->current.end);
pm_parser_err(parser, parser->current.start, parser->current.end + width, PM_ERR_ESCAPE_INVALID_CONTROL);
@@ -9955,10 +9959,6 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
return;
}
case '\\':
- if (flags & PM_ESCAPE_FLAG_CONTROL) {
- pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT);
- return;
- }
parser->current.end++;
if (match(parser, 'u') || match(parser, 'U')) {
@@ -9993,6 +9993,10 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
}
case 'M': {
parser->current.end++;
+ if (flags & PM_ESCAPE_FLAG_META) {
+ pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_META_REPEAT);
+ }
+
if (peek(parser) != '-') {
size_t width = parser->encoding->char_width(parser->current.end, parser->end - parser->current.end);
pm_parser_err(parser, parser->current.start, parser->current.end + width, PM_ERR_ESCAPE_INVALID_META);
@@ -10008,10 +10012,6 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
uint8_t peeked = peek(parser);
switch (peeked) {
case '\\':
- if (flags & PM_ESCAPE_FLAG_META) {
- pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_META_REPEAT);
- return;
- }
parser->current.end++;
if (match(parser, 'u') || match(parser, 'U')) {
@@ -10054,6 +10054,8 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
default: {
if (parser->current.end < parser->end) {
escape_write_escape_encoded(parser, buffer);
+ } else {
+ pm_parser_err_current(parser, PM_ERR_INVALID_ESCAPE_CHARACTER);
}
return;
}