Skip to content

Commit 3200275

Browse files
committed
change(#871-strictMode): cleanup
chore: removed PII from json sample chore: JSONParserConfiguration.java cleanup chore: JSONTokener.java nextValue partial rollback
1 parent d92d62a commit 3200275

File tree

3 files changed

+79
-76
lines changed

3 files changed

+79
-76
lines changed

src/main/java/org/json/JSONParserConfiguration.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ public class JSONParserConfiguration extends ParserConfiguration {
2323
*/
2424
private boolean strictMode;
2525

26-
/**
27-
* Allows Single Quotes when strictMode is true. Has no effect if strictMode is false.
28-
*/
29-
private boolean allowSingleQuotes;
30-
3126
/**
3227
* Configuration with the default values.
3328
*/

src/main/java/org/json/JSONTokener.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public Object nextValue() throws JSONException {
422422
* Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
423423
* JSONObject.NULL object. The strictMode parameter controls the behavior of the method when parsing the value.
424424
*
425-
* @param jsonParserConfiguration which carries options such as strictMode and allowSingleQuotes, these methods will
425+
* @param jsonParserConfiguration which carries options such as strictMode, these methods will
426426
* strictly adhere to the JSON syntax, throwing a JSONException for any deviations.
427427
* @return An object.
428428
* @throws JSONException If syntax error.
@@ -432,10 +432,18 @@ public Object nextValue(JSONParserConfiguration jsonParserConfiguration) throws
432432
switch (c) {
433433
case '{':
434434
this.back();
435-
return getJsonObject(jsonParserConfiguration);
435+
try {
436+
return new JSONObject(this, jsonParserConfiguration);
437+
} catch (StackOverflowError e) {
438+
throw new JSONException("JSON Array or Object depth too large to process.", e);
439+
}
436440
case '[':
437441
this.back();
438-
return getJsonArray();
442+
try {
443+
return new JSONArray(this);
444+
} catch (StackOverflowError e) {
445+
throw new JSONException("JSON Array or Object depth too large to process.", e);
446+
}
439447
default:
440448
return nextSimpleValue(c, jsonParserConfiguration);
441449
}
@@ -445,7 +453,7 @@ public Object nextValue(JSONParserConfiguration jsonParserConfiguration) throws
445453
* This method is used to get a JSONObject from the JSONTokener. The strictMode parameter controls the behavior of
446454
* the method when parsing the JSONObject.
447455
*
448-
* @param jsonParserConfiguration which carries options such as strictMode and allowSingleQuotes, these methods will
456+
* @param jsonParserConfiguration which carries options such as strictMode, these methods will
449457
* strictly adhere to the JSON syntax, throwing a JSONException for any deviations.
450458
* deviations.
451459
* @return A JSONObject which is the next value in the JSONTokener.

src/test/resources/compliantJsonArray.json

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"guid": "441331fb-84d1-4873-a649-3814621a0370",
66
"isActive": true,
77
"balance": "$2,691.63",
8-
"picture": "http://placehold.it/32x32",
8+
"picture": "http://example.abc/32x32",
99
"age": 26,
1010
"eyeColor": "blue",
11-
"name": "Susie Estes",
11+
"name": "abc",
1212
"gender": "female",
13-
"company": "ZENTURY",
14-
"email": "susieestes@zentury.com",
15-
"phone": "+1 (853) 428-2292",
16-
"address": "424 Hewes Street, Grahamtown, Tennessee, 8138",
13+
"company": "example",
14+
"email": "abc@def.com",
15+
"phone": "+1 (123) 456-7890",
16+
"address": "123 Main St",
1717
"about": "Laborum magna tempor officia irure cillum nulla incididunt Lorem dolor veniam elit cupidatat amet. Veniam veniam exercitation nulla consectetur officia esse ex sunt nulla nisi ea cillum nisi reprehenderit. Qui aliquip reprehenderit aliqua aliquip aliquip anim sit magna nostrud dolore veniam velit elit aliquip.\r\n",
1818
"registered": "2016-07-22T03:18:11 -01:00",
1919
"latitude": -21.544934,
@@ -30,18 +30,18 @@
3030
"friends": [
3131
{
3232
"id": 0,
33-
"name": "Simon Garrett"
33+
"name": "abc def"
3434
},
3535
{
3636
"id": 1,
37-
"name": "Conrad Moon"
37+
"name": "ghi jkl"
3838
},
3939
{
4040
"id": 2,
41-
"name": "Mccall Rosario"
41+
"name": "mno pqr"
4242
}
4343
],
44-
"greeting": "Hello, Susie Estes! You have 10 unread messages.",
44+
"greeting": "Hello, abc! You have 10 unread messages.",
4545
"favoriteFruit": "banana"
4646
},
4747
{
@@ -53,12 +53,12 @@
5353
"picture": "http://placehold.it/32x32",
5454
"age": 27,
5555
"eyeColor": "green",
56-
"name": "Irma Greer",
56+
"name": "def",
5757
"gender": "female",
58-
"company": "ANIVET",
59-
"email": "irmagreer@anivet.com",
60-
"phone": "+1 (936) 539-2196",
61-
"address": "285 Roebling Street, Hardyville, Hawaii, 8410",
58+
"company": "sample",
59+
"email": "def@abc.com",
60+
"phone": "+1 (123) 456-78910",
61+
"address": "1234 Main St",
6262
"about": "Ea id cupidatat eiusmod culpa. Nulla consequat esse elit enim et pariatur eiusmod ipsum. Consequat eu non reprehenderit in.\r\n",
6363
"registered": "2015-04-06T07:54:22 -01:00",
6464
"latitude": 83.512347,
@@ -75,18 +75,18 @@
7575
"friends": [
7676
{
7777
"id": 0,
78-
"name": "Terri Morrison"
78+
"name": "sample example"
7979
},
8080
{
8181
"id": 1,
82-
"name": "Foley Turner"
82+
"name": "test name"
8383
},
8484
{
8585
"id": 2,
86-
"name": "Leila Brewer"
86+
"name": "aaa aaaa"
8787
}
8888
],
89-
"greeting": "Hello, Irma Greer! You have 7 unread messages.",
89+
"greeting": "Hello, test! You have 7 unread messages.",
9090
"favoriteFruit": "apple"
9191
},
9292
{
@@ -98,12 +98,12 @@
9898
"picture": "http://placehold.it/32x32",
9999
"age": 32,
100100
"eyeColor": "green",
101-
"name": "Rebecca Garner",
101+
"name": "test",
102102
"gender": "female",
103-
"company": "OCEANICA",
104-
"email": "rebeccagarner@oceanica.com",
105-
"phone": "+1 (868) 551-3810",
106-
"address": "425 Navy Walk, Spokane, Vermont, 7439",
103+
"company": "test",
104+
"email": "test@test.com",
105+
"phone": "+1 (123) 456-7890",
106+
"address": "123 Main St",
107107
"about": "Mollit officia adipisicing ex nisi non Lorem sunt quis est. Irure exercitation duis ipsum qui ullamco eu ea commodo occaecat minim proident. Incididunt nostrud ex cupidatat eiusmod mollit anim irure culpa. Labore voluptate voluptate labore nisi sit eu. Dolor sit proident velit dolor deserunt labore sit ipsum incididunt eiusmod reprehenderit voluptate. Duis anim velit officia laboris consequat officia dolor sint dolor nisi ex.\r\n",
108108
"registered": "2021-11-02T12:50:05 -00:00",
109109
"latitude": -82.969939,
@@ -120,18 +120,18 @@
120120
"friends": [
121121
{
122122
"id": 0,
123-
"name": "Cox Trujillo"
123+
"name": "test"
124124
},
125125
{
126126
"id": 1,
127-
"name": "Stanton Wilcox"
127+
"name": "sample"
128128
},
129129
{
130130
"id": 2,
131-
"name": "Dolores Cooper"
131+
"name": "example"
132132
}
133133
],
134-
"greeting": "Hello, Rebecca Garner! You have 1 unread messages.",
134+
"greeting": "Hello, test! You have 1 unread messages.",
135135
"favoriteFruit": "strawberry"
136136
},
137137
{
@@ -143,12 +143,12 @@
143143
"picture": "http://placehold.it/32x32",
144144
"age": 35,
145145
"eyeColor": "brown",
146-
"name": "Foster Pratt",
146+
"name": "another test",
147147
"gender": "male",
148-
"company": "COMTEST",
149-
"email": "fosterpratt@comtest.com",
150-
"phone": "+1 (829) 400-3497",
151-
"address": "390 Montague Street, Sandston, Wyoming, 9116",
148+
"company": "TEST",
149+
"email": "anothertest@anothertest.com",
150+
"phone": "+1 (321) 987-6543",
151+
"address": "123 Example Main St",
152152
"about": "Do proident consectetur minim quis. In adipisicing culpa Lorem fugiat cillum exercitation velit velit. Non voluptate laboris deserunt veniam et sint consectetur irure aliqua quis eiusmod consectetur elit id. Ex sint do anim Lorem excepteur eu nulla.\r\n",
153153
"registered": "2020-06-25T04:55:25 -01:00",
154154
"latitude": 63.614955,
@@ -165,18 +165,18 @@
165165
"friends": [
166166
{
167167
"id": 0,
168-
"name": "Savage Combs"
168+
"name": "test"
169169
},
170170
{
171171
"id": 1,
172-
"name": "Cecelia Kemp"
172+
"name": "sample"
173173
},
174174
{
175175
"id": 2,
176-
"name": "Priscilla Stephenson"
176+
"name": "example"
177177
}
178178
],
179-
"greeting": "Hello, Foster Pratt! You have 5 unread messages.",
179+
"greeting": "Hello, another test! You have 5 unread messages.",
180180
"favoriteFruit": "apple"
181181
},
182182
{
@@ -185,15 +185,15 @@
185185
"guid": "2c3e5115-758d-468e-99c5-c9afa26e1f9f",
186186
"isActive": true,
187187
"balance": "$1,047.20",
188-
"picture": "http://placehold.it/32x32",
188+
"picture": "http://test.it/32x32",
189189
"age": 30,
190190
"eyeColor": "green",
191-
"name": "Willie Wallace",
191+
"name": "Test Name",
192192
"gender": "female",
193-
"company": "KNEEDLES",
194-
"email": "williewallace@kneedles.com",
195-
"phone": "+1 (816) 510-2695",
196-
"address": "411 Dunne Place, Rosewood, Iowa, 283",
193+
"company": "test",
194+
"email": "testname@testname.com",
195+
"phone": "+1 (999) 999-9999",
196+
"address": "999 Test Main St",
197197
"about": "Voluptate exercitation tempor consectetur velit magna ea occaecat cupidatat consectetur anim aute. Aliquip est aute ipsum laboris non irure qui consectetur tempor quis do ea Lorem. Cupidatat exercitation ad culpa aliqua amet commodo mollit reprehenderit exercitation adipisicing amet et laborum pariatur.\r\n",
198198
"registered": "2023-01-19T02:43:18 -00:00",
199199
"latitude": 14.15208,
@@ -210,18 +210,18 @@
210210
"friends": [
211211
{
212212
"id": 0,
213-
"name": "Burks Lowe"
213+
"name": "test"
214214
},
215215
{
216216
"id": 1,
217-
"name": "Ray Sanchez"
217+
"name": "sample"
218218
},
219219
{
220220
"id": 2,
221-
"name": "Tasha Weiss"
221+
"name": "example"
222222
}
223223
],
224-
"greeting": "Hello, Willie Wallace! You have 6 unread messages.",
224+
"greeting": "Hello, test! You have 6 unread messages.",
225225
"favoriteFruit": "apple"
226226
},
227227
{
@@ -230,15 +230,15 @@
230230
"guid": "816cda74-5d4b-498f-9724-20f340d5f5bf",
231231
"isActive": false,
232232
"balance": "$2,628.74",
233-
"picture": "http://placehold.it/32x32",
233+
"picture": "http://testing.it/32x32",
234234
"age": 28,
235235
"eyeColor": "green",
236-
"name": "Pearl Aguilar",
236+
"name": "Testing",
237237
"gender": "female",
238-
"company": "TELEPARK",
239-
"email": "pearlaguilar@telepark.com",
240-
"phone": "+1 (801) 427-2087",
241-
"address": "633 Highlawn Avenue, Defiance, Illinois, 2118",
238+
"company": "test",
239+
"email": "testing@testing.com",
240+
"phone": "+1 (888) 888-8888",
241+
"address": "123 Main St",
242242
"about": "Cupidatat non ut nulla qui excepteur in minim non et nulla fugiat. Dolor quis laborum occaecat veniam dolor ullamco deserunt amet veniam dolor quis proident tempor laboris. In cillum duis ut quis. Aliqua cupidatat magna proident velit tempor veniam et consequat laborum ex dolore qui. Incididunt deserunt magna minim Lorem consectetur.\r\n",
243243
"registered": "2017-10-14T11:14:08 -01:00",
244244
"latitude": -5.345728,
@@ -255,18 +255,18 @@
255255
"friends": [
256256
{
257257
"id": 0,
258-
"name": "Edwards Wolf"
258+
"name": "test"
259259
},
260260
{
261261
"id": 1,
262-
"name": "Hunter Fitzgerald"
262+
"name": "sample"
263263
},
264264
{
265265
"id": 2,
266-
"name": "Valencia Norton"
266+
"name": "example"
267267
}
268268
],
269-
"greeting": "Hello, Pearl Aguilar! You have 2 unread messages.",
269+
"greeting": "Hello, testing! You have 2 unread messages.",
270270
"favoriteFruit": "strawberry"
271271
},
272272
{
@@ -275,15 +275,15 @@
275275
"guid": "4ee550bc-0920-4104-b3ce-ebf9db6a803f",
276276
"isActive": true,
277277
"balance": "$1,709.31",
278-
"picture": "http://placehold.it/32x32",
278+
"picture": "http://sample.it/32x32",
279279
"age": 31,
280280
"eyeColor": "blue",
281-
"name": "Tanisha Pacheco",
281+
"name": "Sample Name",
282282
"gender": "female",
283-
"company": "VISUALIX",
284-
"email": "tanishapacheco@visualix.com",
285-
"phone": "+1 (867) 577-2549",
286-
"address": "466 Coleridge Street, Dotsero, Delaware, 8574",
283+
"company": "Sample",
284+
"email": "sample@sample.com",
285+
"phone": "+1 (777) 777-7777",
286+
"address": "123 Main St",
287287
"about": "Lorem ex proident ipsum ullamco velit sit nisi eiusmod cillum. Id tempor irure culpa nisi sit non qui veniam non ut. Aliquip reprehenderit excepteur mollit quis excepteur ex sit. Quis do eu veniam do ullamco occaecat eu cupidatat nisi laborum tempor minim fugiat pariatur. Ex in nulla ex velit.\r\n",
288288
"registered": "2019-04-08T03:54:36 -01:00",
289289
"latitude": -70.660321,
@@ -300,18 +300,18 @@
300300
"friends": [
301301
{
302302
"id": 0,
303-
"name": "Carter Galloway"
303+
"name": "Test"
304304
},
305305
{
306306
"id": 1,
307-
"name": "Moody Cameron"
307+
"name": "Sample"
308308
},
309309
{
310310
"id": 2,
311-
"name": "June Gillespie"
311+
"name": "Example"
312312
}
313313
],
314-
"greeting": "Hello, Tanisha Pacheco! You have 6 unread messages.",
314+
"greeting": "Hello, Sample! You have 6 unread messages.",
315315
"favoriteFruit": "apple"
316316
}
317317
]

0 commit comments

Comments
 (0)