Skip to content

Commit e1cb486

Browse files
IlCommittatoreCasaIlCommittatoreCasa
IlCommittatoreCasa
authored and
IlCommittatoreCasa
committed
bug fix issue google#2769
1 parent 84e5f16 commit e1cb486

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-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

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

3131
import com.google.gson.Strictness;
32+
import com.google.gson.internal.bind.TypeAdapters;
33+
3234
import java.io.EOFException;
3335
import java.io.IOException;
3436
import java.io.Reader;
3537
import java.io.StringReader;
38+
import java.io.StringWriter;
3639
import java.util.Arrays;
40+
import java.util.Iterator;
41+
import java.util.stream.Stream;
42+
3743
import org.junit.Ignore;
3844
import org.junit.Test;
3945

@@ -2189,4 +2195,25 @@ private static Reader reader(String s) {
21892195
}
21902196
}; */
21912197
}
2198+
2199+
@Test
2200+
public void testJsonReaderWithStrictnessSetToLenientAndNullValue() throws IOException {
2201+
Iterator<String> iterator = Stream.of(null, "value1", "value2").iterator();
2202+
StringWriter str = new StringWriter();
2203+
2204+
try (JsonWriter writer = new JsonWriter(str)) {
2205+
writer.setStrictness(Strictness.LENIENT);
2206+
while (iterator.hasNext()) {
2207+
TypeAdapters.STRING.write(writer, iterator.next());
2208+
}
2209+
writer.flush();
2210+
}
2211+
2212+
JsonReader reader = new JsonReader(new StringReader(str.toString()));
2213+
reader.setStrictness(Strictness.LENIENT);
2214+
2215+
assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("null");
2216+
assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value1");
2217+
assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value2");
2218+
}
21922219
}

0 commit comments

Comments
 (0)