Skip to content
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

Stack Overflow fix on malformed JSON #48

Merged
merged 1 commit into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/org/codehaus/jettison/json/JSONTokener.java
Expand Up @@ -197,6 +197,9 @@ public char nextClean() throws JSONException {
}
break;
default:
if (!more()) {
throw syntaxError("The JSON text is malformed");
}
back();
return '/';
}
Expand Down
57 changes: 56 additions & 1 deletion src/test/java/org/codehaus/jettison/json/JSONObjectTest.java
Expand Up @@ -92,5 +92,60 @@ public void testForwardSlashEscapingModifiedfBySetter() throws Exception {
assertEquals(obj.toString(), "{\"key\":\"http://example.com/foo\"}");
obj.setEscapeForwardSlashAlways(true);
assertEquals(obj.toString(), "{\"key\":\"http:\\/\\/example.com\\/foo\"}");
}
}

public void testMalformedObject() throws Exception {
try {
new JSONObject("{/");
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}

public void testMalformedObject2() throws Exception {
try {
new JSONObject("{x");
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}

public void testMalformedObject3() throws Exception {
try {
new JSONObject("{/x");
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}

public void testMalformedObject4() throws Exception {
try {
new JSONObject("{/*");
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}

public void testMalformedObject5() throws Exception {
try {
new JSONObject("{//");
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}

public void testMalformedArray() throws Exception {
try {
new JSONObject("{[/");
fail("Failure expected on malformed JSON");
} catch (JSONException ex) {
// expected
}
}

}