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
3 changes: 3 additions & 0 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@ NOINLINE(static) VALUE json_string_unescape(JSON_ParserState *state, JSON_Parser
break;
default:
if ((unsigned char)*pe < 0x20) {
if (*pe == '\n') {
raise_parse_error_at("Invalid unescaped newline character (\\n) in string: %s", state, pe - 1);
}
raise_parse_error_at("invalid ASCII control character in string: %s", state, pe - 1);
}
raise_parse_error_at("invalid escape character in string: %s", state, pe - 1);
Expand Down
8 changes: 8 additions & 0 deletions test/json/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ def test_parse_complex_objects
end
end

def test_parse_control_chars_in_string
0.upto(31) do |ord|
assert_raise JSON::ParserError do
parse(%("#{ord.chr}"))
end
end
end

def test_parse_arrays
assert_equal([1,2,3], parse('[1,2,3]'))
assert_equal([1.2,2,3], parse('[1.2,2,3]'))
Expand Down