diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index 30876109a5..d6f49a13a6 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -1255,6 +1255,7 @@ private void skipUnquotedValue() throws IOException { int i = 0; for (; pos + i < limit; i++) { switch (buffer[pos + i]) { + case '"': case '/': case '\\': case ';': diff --git a/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java b/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java index f8a33be0df..2f5c57190a 100644 --- a/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java +++ b/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java @@ -29,11 +29,15 @@ import static org.junit.Assert.assertThrows; import com.google.gson.Strictness; +import com.google.gson.internal.bind.TypeAdapters; import java.io.EOFException; import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.io.StringWriter; import java.util.Arrays; +import java.util.Iterator; +import java.util.stream.Stream; import org.junit.Ignore; import org.junit.Test; @@ -2170,6 +2174,27 @@ private static void assertDocument(String document, Object... expectations) thro } } + @Test + public void testJsonReaderWithStrictnessSetToLenientAndNullValue() throws IOException { + Iterator iterator = Stream.of(null, "value1", "value2").iterator(); + StringWriter str = new StringWriter(); + + try (JsonWriter writer = new JsonWriter(str)) { + writer.setStrictness(Strictness.LENIENT); + while (iterator.hasNext()) { + TypeAdapters.STRING.write(writer, iterator.next()); + } + writer.flush(); + } + + JsonReader reader = new JsonReader(new StringReader(str.toString())); + reader.setStrictness(Strictness.LENIENT); + + assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("null"); + assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value1"); + assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value2"); + } + /** Returns a reader that returns one character at a time. */ private static Reader reader(String s) { /* if (true) */ return new StringReader(s);