From: Eric Haszlakiewicz Date: Mon, 27 Nov 2017 03:34:43 +0000 (-0500) Subject: Add a few extra cases to test_parse to show how trailing bytes are handled, especiall... X-Git-Tag: json-c-0.13-20171207~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a22858fe77e72388f9e1f2a73576dd135f5bdae;p=json-c Add a few extra cases to test_parse to show how trailing bytes are handled, especially for parsing "Infinity". --- diff --git a/tests/test_parse.c b/tests/test_parse.c index 5eed94e..0d71a47 100644 --- a/tests/test_parse.c +++ b/tests/test_parse.c @@ -43,6 +43,7 @@ static void test_basic_parse() single_basic_parse("\"\003\"", 0); single_basic_parse("/* hello */\"foo\"", 0); single_basic_parse("// hello\n\"foo\"", 0); + single_basic_parse("\"foo\"blue", 0); single_basic_parse("\"\\u0041\\u0042\\u0043\"", 0); // Test with a "short" high surrogate single_basic_parse("[9,'\\uDAD", 0); @@ -57,7 +58,18 @@ static void test_basic_parse() single_basic_parse("-Infinity", 0); single_basic_parse("-infinity", 0); + single_basic_parse("Infinity!", 0); + single_basic_parse("Infinitynull", 0); + single_basic_parse("InfinityXXXX", 0); + single_basic_parse("-Infinitynull", 0); + single_basic_parse("-InfinityXXXX", 0); + single_basic_parse("Infinoodle", 0); + single_basic_parse("InfinAAA", 0); + single_basic_parse("-Infinoodle", 0); + single_basic_parse("-InfinAAA", 0); + single_basic_parse("True", 0); + single_basic_parse("False", 0); single_basic_parse("12", 0); single_basic_parse("12.3", 0); @@ -65,6 +77,13 @@ static void test_basic_parse() /* was returning (int)2015 before patch, should return null */ single_basic_parse("2015-01-15", 0); + /* ...but this works. It's rather inconsistent, and a future major release + * should change the behavior so it either always returns null when extra + * bytes are present (preferred), or always return object created from as much + * as was able to be parsed. + */ + single_basic_parse("12.3xxx", 0); + single_basic_parse("{\"FoO\" : -12.3E512}", 0); single_basic_parse("{\"FoO\" : -12.3E51.2}", 0); /* non-sensical, returns null */ single_basic_parse("[\"\\n\"]", 0); diff --git a/tests/test_parse.expected b/tests/test_parse.expected index 46fe2ef..cc13cf3 100644 --- a/tests/test_parse.expected +++ b/tests/test_parse.expected @@ -2,6 +2,7 @@ new_obj.to_string("")="\u0003" new_obj.to_string(/* hello */"foo")="foo" new_obj.to_string(// hello "foo")="foo" +new_obj.to_string("foo"blue)="foo" new_obj.to_string("\u0041\u0042\u0043")="ABC" new_obj.to_string([9,'\uDAD)=null new_obj.to_string(null)=null @@ -13,11 +14,22 @@ new_obj.to_string(Infinity)=Infinity new_obj.to_string(infinity)=Infinity new_obj.to_string(-Infinity)=-Infinity new_obj.to_string(-infinity)=-Infinity +new_obj.to_string(Infinity!)=Infinity +new_obj.to_string(Infinitynull)=Infinity +new_obj.to_string(InfinityXXXX)=Infinity +new_obj.to_string(-Infinitynull)=-Infinity +new_obj.to_string(-InfinityXXXX)=-Infinity +new_obj.to_string(Infinoodle)=null +new_obj.to_string(InfinAAA)=null +new_obj.to_string(-Infinoodle)=null +new_obj.to_string(-InfinAAA)=null new_obj.to_string(True)=true +new_obj.to_string(False)=false new_obj.to_string(12)=12 new_obj.to_string(12.3)=12.3 new_obj.to_string(12.3.4)=null new_obj.to_string(2015-01-15)=null +new_obj.to_string(12.3xxx)=12.3 new_obj.to_string({"FoO" : -12.3E512})={ "FoO": -12.3E512 } new_obj.to_string({"FoO" : -12.3E51.2})=null new_obj.to_string(["\n"])=[ "\n" ]