Enhancing the json reader, adding corresponding test case for it

This commit is contained in:
Archit Dey 2016-05-23 00:47:02 -07:00 committed by jwilson
parent daa92e3fdc
commit 3f8726ecaf
2 changed files with 19 additions and 1 deletions

View File

@ -1561,8 +1561,11 @@ public class JsonReader implements Closeable {
case '\'':
case '"':
case '\\':
case '/':
return escaped;
default:
return escaped;
// throw error when none of the above cases are matched
throw syntaxError("Invalid escape sequence");
}
}

View File

@ -174,6 +174,21 @@ public final class JsonReaderTest extends TestCase {
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() {
try {
new JsonReader(null);