Enhancing the json reader, adding corresponding test case for it
This commit is contained in:
parent
daa92e3fdc
commit
3f8726ecaf
|
@ -1561,8 +1561,11 @@ public class JsonReader implements Closeable {
|
||||||
case '\'':
|
case '\'':
|
||||||
case '"':
|
case '"':
|
||||||
case '\\':
|
case '\\':
|
||||||
default:
|
case '/':
|
||||||
return escaped;
|
return escaped;
|
||||||
|
default:
|
||||||
|
// throw error when none of the above cases are matched
|
||||||
|
throw syntaxError("Invalid escape sequence");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,21 @@ public final class JsonReaderTest extends TestCase {
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInvalidJsonInput() throws IOException {
|
||||||
|
String json = "{\n"
|
||||||
|
+ " \"h\\ello\": true,\n"
|
||||||
|
+ " \"foo\": [\"world\"]\n"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
JsonReader reader = new JsonReader(reader(json));
|
||||||
|
reader.beginObject();
|
||||||
|
try {
|
||||||
|
reader.nextName();
|
||||||
|
fail();
|
||||||
|
} catch (IOException expected) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testNulls() {
|
public void testNulls() {
|
||||||
try {
|
try {
|
||||||
new JsonReader(null);
|
new JsonReader(null);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user