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 @@ -630,7 +630,7 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c
unescape = (char *) "\f";
break;
case 'u':
if (pe > stringEnd - 4) {
if (pe > stringEnd - 5) {
raise_parse_error("incomplete unicode character escape sequence at '%s'", p);
} else {
uint32_t ch = unescape_unicode((unsigned char *) ++pe);
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 @@ -302,6 +302,14 @@ def test_parse_broken_string
end
end

def test_invalid_unicode_escape
assert_raise(JSON::ParserError) { parse('"\u"') }
assert_raise(JSON::ParserError) { parse('"\ua"') }
assert_raise(JSON::ParserError) { parse('"\uaa"') }
assert_raise(JSON::ParserError) { parse('"\uaaa"') }
assert_equal "\uaaaa", parse('"\uaaaa"')
end

def test_parse_big_integers
json1 = JSON(orig = (1 << 31) - 1)
assert_equal orig, parse(json1)
Expand Down
Loading