feat(#871-strictMode): enhanced and simplified strictMode logic

This commit is contained in:
rikkarth
2024-03-30 10:15:10 +00:00
parent 49de92224d
commit 372f5caac4
2 changed files with 84 additions and 127 deletions

View File

@@ -225,14 +225,7 @@ public class JSONObject {
case '}':
return;
default:
String keyToValidate = getKeyToValidate(x, c, jsonParserConfiguration.isStrictMode());
boolean keyHasQuotes = keyToValidate.startsWith("\"") && keyToValidate.endsWith("\"");
if (jsonParserConfiguration.isStrictMode() && !keyHasQuotes) {
throw new JSONException("Key is not surrounded by quotes: " + keyToValidate);
}
key = keyToValidate;
key = x.nextSimpleValue(c, jsonParserConfiguration.isStrictMode()).toString();
}
// The key is followed by ':'.
@@ -285,11 +278,6 @@ public class JSONObject {
}
return x.nextValue();
}
private String getKeyToValidate(JSONTokener x, char c, boolean strictMode) {
return x.nextSimpleValue(c, strictMode).toString();
}
/**
* Construct a JSONObject from a Map.
*