Merge branch 'deyboy90-master'

* deyboy90-master:
  Enhancing the json reader, adding corresponding test case for it
This commit is contained in:
jwilson 2016-06-02 09:20:06 -04:00
commit 86ccf826fc
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);