Skip to content

Commit f64791e

Browse files
author
“@IlCommittatore”
committed
fix
1 parent 84e5f16 commit f64791e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

gson/src/main/java/com/google/gson/stream/JsonReader.java

+1
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ private String nextUnquotedValue() throws IOException {
11721172
while (true) {
11731173
for (; pos + i < limit; i++) {
11741174
switch (buffer[pos + i]) {
1175+
case '"':
11751176
case '/':
11761177
case '\\':
11771178
case ';':

gson/src/test/java/com/google/gson/stream/JsonReaderTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
import static org.junit.Assert.assertThrows;
3030

3131
import com.google.gson.Strictness;
32+
import com.google.gson.internal.bind.TypeAdapters;
3233
import java.io.EOFException;
3334
import java.io.IOException;
3435
import java.io.Reader;
3536
import java.io.StringReader;
37+
import java.io.StringWriter;
3638
import java.util.Arrays;
39+
import java.util.Iterator;
40+
import java.util.stream.Stream;
3741
import org.junit.Ignore;
3842
import org.junit.Test;
3943

@@ -2170,6 +2174,27 @@ private static void assertDocument(String document, Object... expectations) thro
21702174
}
21712175
}
21722176

2177+
@Test
2178+
public void testJsonReaderWithStrictnessSetToLenientAndNullValue() throws IOException {
2179+
Iterator<String> iterator = Stream.of(null, "value1", "value2").iterator();
2180+
StringWriter str = new StringWriter();
2181+
2182+
try (JsonWriter writer = new JsonWriter(str)) {
2183+
writer.setStrictness(Strictness.LENIENT);
2184+
while (iterator.hasNext()) {
2185+
TypeAdapters.STRING.write(writer, iterator.next());
2186+
}
2187+
writer.flush();
2188+
}
2189+
2190+
JsonReader reader = new JsonReader(new StringReader(str.toString()));
2191+
reader.setStrictness(Strictness.LENIENT);
2192+
2193+
assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("null");
2194+
assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value1");
2195+
assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value2");
2196+
}
2197+
21732198
/** Returns a reader that returns one character at a time. */
21742199
private static Reader reader(String s) {
21752200
/* if (true) */ return new StringReader(s);

0 commit comments

Comments
 (0)