Skip to content

Commit 39ee5e0

Browse files
authored
Merge pull request #911 from stleary/revert-strict-mode-for-now
Revert strict mode
2 parents 14f7127 + 215ec9b commit 39ee5e0

15 files changed

+226
-1196
lines changed

src/main/java/org/json/JSONArray.java

Lines changed: 70 additions & 134 deletions
Large diffs are not rendered by default.

src/main/java/org/json/JSONObject.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration
220220
for (;;) {
221221
c = x.nextClean();
222222
switch (c) {
223-
case 0:
224-
throw x.syntaxError("A JSONObject text must end with '}'");
225-
case '}':
226-
return;
227-
default:
228-
key = x.nextSimpleValue(c, jsonParserConfiguration).toString();
223+
case 0:
224+
throw x.syntaxError("A JSONObject text must end with '}'");
225+
case '}':
226+
return;
227+
default:
228+
key = x.nextSimpleValue(c).toString();
229229
}
230230

231231
// The key is followed by ':'.
@@ -244,7 +244,7 @@ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration
244244
throw x.syntaxError("Duplicate key \"" + key + "\"");
245245
}
246246

247-
Object value = x.nextValue(jsonParserConfiguration);
247+
Object value = x.nextValue();
248248
// Only add value if non-null
249249
if (value != null) {
250250
this.put(key, value);
@@ -1247,7 +1247,7 @@ public BigDecimal optBigDecimal(String key, BigDecimal defaultValue) {
12471247
static BigDecimal objectToBigDecimal(Object val, BigDecimal defaultValue) {
12481248
return objectToBigDecimal(val, defaultValue, true);
12491249
}
1250-
1250+
12511251
/**
12521252
* @param val value to convert
12531253
* @param defaultValue default value to return is the conversion doesn't work or is null.

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,11 @@
44
* Configuration object for the JSON parser. The configuration is immutable.
55
*/
66
public class JSONParserConfiguration extends ParserConfiguration {
7-
8-
/** Original Configuration of the JSON Parser. */
9-
public static final JSONParserConfiguration ORIGINAL = new JSONParserConfiguration();
10-
11-
/** Original configuration of the JSON Parser except that values are kept as strings. */
12-
public static final JSONParserConfiguration KEEP_STRINGS = new JSONParserConfiguration().withKeepStrings(true);
13-
147
/**
158
* Used to indicate whether to overwrite duplicate key or not.
169
*/
1710
private boolean overwriteDuplicateKey;
1811

19-
/**
20-
* This flag, when set to true, instructs the parser to throw a JSONException if it encounters an invalid character
21-
* immediately following the final ']' character in the input. This is useful for ensuring strict adherence to the
22-
* JSON syntax, as any characters after the final closing bracket of a JSON array are considered invalid.
23-
*/
24-
private boolean strictMode;
25-
2612
/**
2713
* Configuration with the default values.
2814
*/
@@ -72,24 +58,6 @@ public JSONParserConfiguration withOverwriteDuplicateKey(final boolean overwrite
7258
return clone;
7359
}
7460

75-
76-
/**
77-
* Sets the strict mode configuration for the JSON parser.
78-
* <p>
79-
* When strict mode is enabled, the parser will throw a JSONException if it encounters an invalid character
80-
* immediately following the final ']' character in the input. This is useful for ensuring strict adherence to the
81-
* JSON syntax, as any characters after the final closing bracket of a JSON array are considered invalid.
82-
*
83-
* @param mode a boolean value indicating whether strict mode should be enabled or not
84-
* @return a new JSONParserConfiguration instance with the updated strict mode setting
85-
*/
86-
public JSONParserConfiguration withStrictMode(final boolean mode) {
87-
JSONParserConfiguration clone = this.clone();
88-
clone.strictMode = mode;
89-
90-
return clone;
91-
}
92-
9361
/**
9462
* The parser's behavior when meeting duplicate keys, controls whether the parser should
9563
* overwrite duplicate keys or not.
@@ -99,18 +67,4 @@ public JSONParserConfiguration withStrictMode(final boolean mode) {
9967
public boolean isOverwriteDuplicateKey() {
10068
return this.overwriteDuplicateKey;
10169
}
102-
103-
104-
/**
105-
* Retrieves the current strict mode setting of the JSON parser.
106-
* <p>
107-
* Strict mode, when enabled, instructs the parser to throw a JSONException if it encounters an invalid character
108-
* immediately following the final ']' character in the input. This ensures strict adherence to the JSON syntax, as
109-
* any characters after the final closing bracket of a JSON array are considered invalid.
110-
*
111-
* @return the current strict mode setting. True if strict mode is enabled, false otherwise.
112-
*/
113-
public boolean isStrictMode() {
114-
return this.strictMode;
115-
}
11670
}

0 commit comments

Comments
 (0)