File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -256,6 +256,9 @@ public JSONObject(JSONTokener x) throws JSONException {
256256 if (x .nextClean () == '}' ) {
257257 return ;
258258 }
259+ if (x .end ()) {
260+ throw x .syntaxError ("A JSONObject text must end with '}'" );
261+ }
259262 x .back ();
260263 break ;
261264 case '}' :
Original file line number Diff line number Diff line change @@ -2225,6 +2225,15 @@ public void jsonObjectParsingErrors() {
22252225 "Expected a ',' or '}' at 15 [character 16 line 1]" ,
22262226 e .getMessage ());
22272227 }
2228+ try {
2229+ // \0 after ,
2230+ String str = "{\" myKey\" :true, \0 \" myOtherKey\" :false}" ;
2231+ assertNull ("Expected an exception" ,new JSONObject (str ));
2232+ } catch (JSONException e ) {
2233+ assertEquals ("Expecting an exception message" ,
2234+ "A JSONObject text must end with '}' at 15 [character 16 line 1]" ,
2235+ e .getMessage ());
2236+ }
22282237 try {
22292238 // append to wrong key
22302239 String str = "{\" myKey\" :true, \" myOtherKey\" :false}" ;
You can’t perform that action at this time.
0 commit comments