Apply explicit parser configuration to nested values - #1077
Mahmoodifar wants to merge 2 commits into
Conversation
| */ | ||
| JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration, boolean isInitial) throws JSONException { | ||
| this(); | ||
| x.setJsonParserConfiguration(jsonParserConfiguration); |
There was a problem hiding this comment.
Please restore the original JSONParserConfiguration to JSONTokener before returning.
| */ | ||
| JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration, boolean isInitial) throws JSONException { | ||
| this(); | ||
| x.setJsonParserConfiguration(jsonParserConfiguration); |
There was a problem hiding this comment.
Please restore the original JSONParserConfiguration to JSONTokener before returning.
| */ | ||
| JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration, boolean isInitial) throws JSONException { | ||
| this(); | ||
| x.setJsonParserConfiguration(jsonParserConfiguration); |
There was a problem hiding this comment.
JSONTokener.setParserConfiguration() is deprecated. Please add and use a new method that does the same thing, but make it package-private.
|
@Mahmoodifar Thanks for the PR. Looks good, a couple of minor items to address. |
|
|
What problem does this code solve? Risks Changes to the Existing Behavior Changes to the API Will this require a new release? Should the documentation be updated? Unit Tests Refactoring Review status Starting 3-day comment window |



When a JSONObject or JSONArray constructor receives both a JSONTokener and an explicit parser configuration, nested values still use the tokener's previous configuration. For example, strict parsing can accept single-quoted values.
Apply the supplied configuration throughout construction, including nested values, using a package-private setter. Restore the tokener's original configuration in a finally block on both success and failure, and document this behavior.
Fixes #945.
Regression coverage includes strict and lenient overrides, nested duplicate keys, sibling values, empty containers, malformed input, trailing content, and reuse of the tokener after construction.
Validation on Java 17:
mvn -B -ntp clean testmvn -B -ntp test -Ptest-strict-mode javadoc:jar@attach-javadocsBoth suites: 804 tests, 6 skipped, no failures or errors. Javadocs built successfully. Five configuration-restoration tests failed before the follow-up fix.