diff options
author | tompng <[email protected]> | 2025-01-20 20:44:37 +0900 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-01-20 14:20:55 +0100 |
commit | 525d7a68e4e08aca39ef8ec6af1e78d489cf0bd5 (patch) | |
tree | bacf151b2c94cefb5d4337a941ba336106bbe44c /ext/json/parser/parser.c | |
parent | c026e44bb557dc42516785beba00452fa462738e (diff) |
[ruby/json] Raise parse error on invalid comments
https://github.com/ruby/json/commit/2f57f40467
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12602
Diffstat (limited to 'ext/json/parser/parser.c')
-rw-r--r-- | ext/json/parser/parser.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index de72edf4e7..351b7f6fac 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -476,7 +476,7 @@ static const bool whitespace[256] = { ['/'] = 1, }; -static bool +static void json_eat_comments(JSON_ParserState *state) { if (state->cursor + 1 < state->end) { @@ -496,7 +496,7 @@ json_eat_comments(JSON_ParserState *state) state->cursor = memchr(state->cursor, '*', state->end - state->cursor); if (!state->cursor) { state->cursor = state->end; - break; + raise_parse_error("unexpected end of input, expected closing '*/'", state->cursor); } else { state->cursor++; if (state->cursor < state->end && *state->cursor == '/') { @@ -508,10 +508,12 @@ json_eat_comments(JSON_ParserState *state) break; } default: - return false; + raise_parse_error("unexpected token at '%s'", state->cursor); + break; } + } else { + raise_parse_error("unexpected token at '%s'", state->cursor); } - return true; } static inline void @@ -521,9 +523,7 @@ json_eat_whitespace(JSON_ParserState *state) if (RB_LIKELY(*state->cursor != '/')) { state->cursor++; } else { - if (!json_eat_comments(state)) { - return; - } + json_eat_comments(state); } } } |