diff --git a/yarp/yarp.c b/yarp/yarp.c index 2573663f26..dd27c172f4 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -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;