summaryrefslogtreecommitdiff
path: root/yarp
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2023-09-15 12:30:17 -0400
committergit <[email protected]>2023-09-15 22:59:48 +0000
commit1be64e34d0881e5c66be51a892bcd3a056e8f5f0 (patch)
tree76793914f7d0f05a7c61826573d41fbda0f353ea /yarp
parent18780c22f657be2a0251fbf174fb46fd8523fae7 (diff)
[ruby/yarp] Alnum cannot be %-literal delimiters
https://github.com/ruby/yarp/commit/4ba6d5ca70
Diffstat (limited to 'yarp')
-rw-r--r--yarp/yarp.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/yarp/yarp.c b/yarp/yarp.c
index b343566ee0..7c4b347678 100644
--- a/yarp/yarp.c
+++ b/yarp/yarp.c
@@ -7077,9 +7077,10 @@ parser_lex(yp_parser_t *parser) {
// % %= %i %I %q %Q %w %W
case '%': {
- // If there is no subsequent character then we have an invalid token. We're
- // going to say it's the percent operator because we don't want to move into the
- // string lex mode unnecessarily.
+ // If there is no subsequent character then we have an
+ // invalid token. We're going to say it's the percent
+ // operator because we don't want to move into the string
+ // lex mode unnecessarily.
if ((lex_state_beg_p(parser) || lex_state_arg_p(parser)) && (parser->current.end >= parser->end)) {
yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, YP_ERR_INVALID_PERCENT);
LEX(YP_TOKEN_PERCENT);
@@ -7110,6 +7111,14 @@ parser_lex(yp_parser_t *parser) {
}
}
+ // Delimiters for %-literals cannot be alphanumeric. We
+ // validate that here.
+ uint8_t delimiter = peek_offset(parser, 1);
+ if (delimiter >= 0x80 || parser->encoding.alnum_char(&delimiter, 1)) {
+ yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, YP_ERR_INVALID_PERCENT);
+ goto lex_next_token;
+ }
+
switch (peek(parser)) {
case 'i': {
parser->current.end++;