Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ ALWAYS_INLINE(static) bool json_parse_any(JSON_ParserState *state, JSON_ParserCo
if (RB_LIKELY(peek(state) == '"')) {
VALUE string = json_parse_string(state, config, true);
if (UNDEF_P(string)) {
if (resumable) {
if (resumable && eos(state)) {
state->cursor = start;
return false;
} else {
Expand Down
13 changes: 13 additions & 0 deletions test/json/resumable_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_parse_byte_by_byte_object
assert_resumed_parsing('{ }')
assert_resumed_parsing('{"test" : true}')
assert_resumed_parsing('{ "test":12, "value" : { "key": 42} }')
assert_resumed_parsing('{"te\u0000st":true}')
end

def test_parse_byte_by_byte_string
Expand Down Expand Up @@ -226,6 +227,18 @@ def test_nul_byte_is_a_syntax_error
assert_parse_error "{\"a\":1,\x00}" # object key after ','
end

def test_nul_after_backslash_in_object_key_is_a_syntax_error
assert_parse_error "{\"key\\\x00\":1}"
assert_parse_error "{\"a\":1,\"key\\\x00\":2}"
end

def test_nul_after_backslash_in_object_key_across_feeds
@parser << "{\"key\\"
refute @parser.parse
@parser << "\x00\":1}"
assert_raise(JSON::ParserError) { @parser.parse }
end

def test_incomplete_input_at_structural_positions_resumes
# Counterpart of test_nul_byte_is_a_syntax_error: a genuine EOS at the same positions must
# stay incomplete (return false), not raise -- this is what distinguishes EOS from a NUL.
Expand Down
Loading