diff --git a/src/main/java/org/json/JSONParserConfiguration.java b/src/main/java/org/json/JSONParserConfiguration.java index 3b32eab..17c2f73 100644 --- a/src/main/java/org/json/JSONParserConfiguration.java +++ b/src/main/java/org/json/JSONParserConfiguration.java @@ -6,12 +6,10 @@ package org.json; public class JSONParserConfiguration extends ParserConfiguration { /** Original Configuration of the JSON Parser. */ - public static final JSONParserConfiguration ORIGINAL - = new JSONParserConfiguration(); + public static final JSONParserConfiguration ORIGINAL = new JSONParserConfiguration(); /** Original configuration of the JSON Parser except that values are kept as strings. */ - public static final JSONParserConfiguration KEEP_STRINGS - = new JSONParserConfiguration().withKeepStrings(true); + public static final JSONParserConfiguration KEEP_STRINGS = new JSONParserConfiguration().withKeepStrings(true); /** * Used to indicate whether to overwrite duplicate key or not. @@ -97,24 +95,6 @@ public class JSONParserConfiguration extends ParserConfiguration { return clone; } - /** - * Allows single quotes mode configuration for JSON parser when strictMode is on. - *
- * If this option is set to true when strict Mode is enabled, the parser will allow single quoted fields. - *
- * This option is false by default. - * - * @param mode a boolean value indicating whether single quotes should be allowed or not - * @return a new JSONParserConfiguration instance with the updated strict mode setting - */ - public JSONParserConfiguration allowSingleQuotes(final boolean mode) { - JSONParserConfiguration clone = this.clone(); - clone.strictMode = this.strictMode; - clone.allowSingleQuotes = mode; - - return clone; - } - /** * The parser's behavior when meeting duplicate keys, controls whether the parser should * overwrite duplicate keys or not. @@ -138,14 +118,4 @@ public class JSONParserConfiguration extends ParserConfiguration { public boolean isStrictMode() { return this.strictMode; } - - /** - * Retrieves the allow single quotes option. - *
- * Allow Single Quotes, when enabled during strict mode, instructs the parser to allow single quoted JSON fields. - * The parser will not throw a JSONException if compliant single quoted fields are found in the JSON structure. - * - * @return the current allow single quotes setting. - */ - public boolean isAllowSingleQuotes() {return this.allowSingleQuotes;} } diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 36352ad..b825ee2 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -472,9 +472,8 @@ public class JSONTokener { Object nextSimpleValue(char c, JSONParserConfiguration jsonParserConfiguration) { boolean strictMode = jsonParserConfiguration.isStrictMode(); - boolean allowSingleQuotes = jsonParserConfiguration.isAllowSingleQuotes(); - if(strictMode && !allowSingleQuotes && c == '\''){ + if(strictMode && c == '\''){ throw this.syntaxError("Single quote wrap not allowed in strict mode"); } diff --git a/src/test/java/org/json/junit/JSONParserConfigurationTest.java b/src/test/java/org/json/junit/JSONParserConfigurationTest.java index 64723c7..1ce289e 100644 --- a/src/test/java/org/json/junit/JSONParserConfigurationTest.java +++ b/src/test/java/org/json/junit/JSONParserConfigurationTest.java @@ -118,24 +118,36 @@ public class JSONParserConfigurationTest { } @Test - public void givenUnbalancedQuotes_testStrictModeTrueAndAllowSingleQuotes_shouldThrowJsonExceptionWtihConcreteErrorDescription() { + public void givenNonCompliantQuotes_testStrictModeTrue_shouldThrowJsonExceptionWithConcreteErrorDescription() { JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true).allowSingleQuotes(true); + .withStrictMode(true); String testCaseOne = "[\"abc', \"test\"]"; String testCaseTwo = "['abc\", \"test\"]"; + String testCaseThree = "['abc']"; + String testCaseFour = "[{'testField': \"testValue\"}]"; JSONException jeOne = assertThrows(JSONException.class, () -> new JSONArray(testCaseOne, jsonParserConfiguration)); JSONException jeTwo = assertThrows(JSONException.class, () -> new JSONArray(testCaseTwo, jsonParserConfiguration)); + JSONException jeThree = assertThrows(JSONException.class, + () -> new JSONArray(testCaseThree, jsonParserConfiguration)); + JSONException jeFour = assertThrows(JSONException.class, + () -> new JSONArray(testCaseFour, jsonParserConfiguration)); assertEquals( "Field contains unbalanced quotes. Starts with \" but ends with single quote. at 6 [character 7 line 1]", jeOne.getMessage()); assertEquals( - "Field contains unbalanced quotes. Starts with ' but ends with double quote. at 6 [character 7 line 1]", + "Single quote wrap not allowed in strict mode at 2 [character 3 line 1]", jeTwo.getMessage()); + assertEquals( + "Single quote wrap not allowed in strict mode at 2 [character 3 line 1]", + jeThree.getMessage()); + assertEquals( + "Single quote wrap not allowed in strict mode at 3 [character 4 line 1]", + jeFour.getMessage()); } @Test