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
4 changes: 2 additions & 2 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,13 +1046,13 @@ NOINLINE(static) VALUE json_string_unescape(JSON_ParserState *state, JSON_Parser
p = ++pe;
break;
}
case 0:
return Qundef;
default:
if ((unsigned char)*pe < 0x20) {
if (!config->allow_control_characters) {
if (*pe == '\n') {
raise_syntax_error_at("Invalid unescaped newline character (\\n) in string: %s", state, pe - 1);
} else if (*pe == '\0') {
raise_syntax_error_at("Invalid unescaped NULL character (\\0) in string: %s", state, pe - 1);
}
raise_syntax_error_at("invalid ASCII control character in string: %s", state, pe - 1);
}
Expand Down
2 changes: 2 additions & 0 deletions test/json/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def test_parse_control_char_and_backslash
end

JSON.parse(%("#{'a' * 30}#{backslash_and_control_char}"), allow_control_characters: true, allow_invalid_escape: true)

assert_equal ["a\u0000b", 2], JSON.parse("[\"a\\\x00b\", 2]", allow_control_characters: true, allow_invalid_escape: true)
end

def test_parse_invalid_escape
Expand Down
Loading