diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index 1398b6b3..907bd047 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -476,7 +476,7 @@ static const bool whitespace[256] = { ['/'] = 1, }; -static void +static bool json_eat_comments(JSON_ParserState *state) { if (state->cursor + 1 < state->end) { @@ -508,9 +508,10 @@ json_eat_comments(JSON_ParserState *state) break; } default: - return; + return false; } } + return true; } static inline void @@ -520,7 +521,9 @@ json_eat_whitespace(JSON_ParserState *state) if (RB_LIKELY(*state->cursor != '/')) { state->cursor++; } else { - json_eat_comments(state); + if (!json_eat_comments(state)) { + return; + } } } } diff --git a/test/json/json_parser_test.rb b/test/json/json_parser_test.rb index 59562008..c5ce0232 100644 --- a/test/json/json_parser_test.rb +++ b/test/json/json_parser_test.rb @@ -629,6 +629,13 @@ def test_parse_error_incomplete_hash end end + def test_parse_leading_slash + # ref: https://github.com/ruby/ruby/pull/12598 + assert_raise(JSON::ParserError) do + JSON.parse("/foo/bar") + end + end + private def string_deduplication_available?