[ruby/yarp] Make sure lexing ? does not read off the end

https://github.com/ruby/yarp/commit/d694e3ebf2
This commit is contained in:
Kevin Newton 2023-08-03 10:35:56 -04:00 committed by Takashi Kokubun
parent d2eb82d969
commit 3f64defe13
Notes: git 2023-08-17 00:48:07 +00:00

View File

@ -5307,11 +5307,15 @@ lex_question_mark(yp_parser_t *parser) {
return YP_TOKEN_CHARACTER_LITERAL;
} else {
size_t encoding_width = parser->encoding.char_width(parser->current.end);
// We only want to return a character literal if there's exactly one
// alphanumeric character right after the `?`
if (
!parser->encoding.alnum_char(parser->current.end) ||
!parser->encoding.alnum_char(parser->current.end + encoding_width)
(
(parser->current.end + encoding_width >= parser->end) ||
!parser->encoding.alnum_char(parser->current.end + encoding_width)
)
) {
lex_state_set(parser, YP_LEX_STATE_END);
parser->current.end += encoding_width;