Skip to content

Commit c026e44

Browse files
tompngbyroot
authored andcommitted
[ruby/json] Fix parsing incomplete unicode escape "\uaaa"
ruby/json@86c0d4eb7e
1 parent 2b4b7bd commit c026e44

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ext/json/parser/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c
630630
unescape = (char *) "\f";
631631
break;
632632
case 'u':
633-
if (pe > stringEnd - 4) {
633+
if (pe > stringEnd - 5) {
634634
raise_parse_error("incomplete unicode character escape sequence at '%s'", p);
635635
} else {
636636
uint32_t ch = unescape_unicode((unsigned char *) ++pe);

test/json/json_parser_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ def test_parse_broken_string
302302
end
303303
end
304304

305+
def test_invalid_unicode_escape
306+
assert_raise(JSON::ParserError) { parse('"\u"') }
307+
assert_raise(JSON::ParserError) { parse('"\ua"') }
308+
assert_raise(JSON::ParserError) { parse('"\uaa"') }
309+
assert_raise(JSON::ParserError) { parse('"\uaaa"') }
310+
assert_equal "\uaaaa", parse('"\uaaaa"')
311+
end
312+
305313
def test_parse_big_integers
306314
json1 = JSON(orig = (1 << 31) - 1)
307315
assert_equal orig, parse(json1)

0 commit comments

Comments
 (0)