-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Update JSONArray.java for #1007 #1008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fix array content starting with ',' in strict mode
|
| if (nextChar == 0) { | ||
| // array is unclosed. No ']' found, instead EOF | ||
| throw x.syntaxError("Expected a ',' or ']'"); | ||
| } else if (nextChar==',' && jsonParserConfiguration.isStrictMode()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add at least one test case to JSONArrayTest.java to provide coverage for the new code
For example, this tests both jsonobject and jsonarray, with and without strict mode. It also handles the 'TestWithStrictMode' gradle task where strict mode is always set.
@Test
public void foo() {
String s = "{\"a\":[ ,4,null,8]}";
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration();
if (jsonParserConfiguration.isStrictMode()) {
// expect an error during strict mode testing
assertThrows(JSONException.class, () -> { new JSONObject(s); });
} else {
new JSONObject(s);
}
assertThrows(JSONException.class, () -> { new JSONObject(s, new JSONParserConfiguration().withStrictMode(true)); });
String s2 = "[,4,null,8]";
if (jsonParserConfiguration.isStrictMode()) {
// expect an error during strict mode testing
assertThrows(JSONException.class, () -> { new JSONArray(s2); });
} else {
new JSONArray(s2);
}
assertThrows(JSONException.class, () -> { new JSONArray(s2, new JSONParserConfiguration().withStrictMode(true)); });
}
|
What problem does this code solve? Does the code still compile with Java6? Risks Changes to the API? Will this require a new release? Should the documentation be updated? Does it break the unit tests? Was any code refactored in this commit? Review status Starting 3-day comment window |
|
@eleumik PR is approved, but please add unit test coverage if you get a chance. Otherwise, I will add it after the merge. |
stleary
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open comments will be addressed in a future commit



fix array content starting with ',' in strict mode