[ruby/yarp] Alnum cannot be %-literal delimiters
https://github.com/ruby/yarp/commit/4ba6d5ca70
This commit is contained in:
parent
18780c22f6
commit
1be64e34d0
@ -1255,6 +1255,20 @@ module YARP
|
|||||||
assert_error_messages "0x1_1_", error_messages
|
assert_error_messages "0x1_1_", error_messages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_alnum_delimiters
|
||||||
|
error_messages = ["Invalid `%` token"]
|
||||||
|
|
||||||
|
assert_error_messages "%qXfooX", error_messages
|
||||||
|
assert_error_messages "%QXfooX", error_messages
|
||||||
|
assert_error_messages "%wXfooX", error_messages
|
||||||
|
assert_error_messages "%WxfooX", error_messages
|
||||||
|
assert_error_messages "%iXfooX", error_messages
|
||||||
|
assert_error_messages "%IXfooX", error_messages
|
||||||
|
assert_error_messages "%xXfooX", error_messages
|
||||||
|
assert_error_messages "%rXfooX", error_messages
|
||||||
|
assert_error_messages "%sXfooX", error_messages
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
||||||
|
15
yarp/yarp.c
15
yarp/yarp.c
@ -7077,9 +7077,10 @@ parser_lex(yp_parser_t *parser) {
|
|||||||
|
|
||||||
// % %= %i %I %q %Q %w %W
|
// % %= %i %I %q %Q %w %W
|
||||||
case '%': {
|
case '%': {
|
||||||
// If there is no subsequent character then we have an invalid token. We're
|
// If there is no subsequent character then we have an
|
||||||
// going to say it's the percent operator because we don't want to move into the
|
// invalid token. We're going to say it's the percent
|
||||||
// string lex mode unnecessarily.
|
// 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)) {
|
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);
|
yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, YP_ERR_INVALID_PERCENT);
|
||||||
LEX(YP_TOKEN_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)) {
|
switch (peek(parser)) {
|
||||||
case 'i': {
|
case 'i': {
|
||||||
parser->current.end++;
|
parser->current.end++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user