Skip to content

Commit

Permalink
bug fix issue #2769
Browse files Browse the repository at this point in the history
  • Loading branch information
IlCommittatoreCasa authored and IlCommittatoreCasa committed Dec 2, 2024
1 parent 84e5f16 commit e1cb486
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions gson/src/main/java/com/google/gson/stream/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,7 @@ private String nextUnquotedValue() throws IOException {
while (true) {
for (; pos + i < limit; i++) {
switch (buffer[pos + i]) {
case '"':
case '/':
case '\\':
case ';':
Expand Down
27 changes: 27 additions & 0 deletions gson/src/test/java/com/google/gson/stream/JsonReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@
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;

Expand Down Expand Up @@ -2189,4 +2195,25 @@ private static Reader reader(String s) {
}
}; */
}

@Test
public void testJsonReaderWithStrictnessSetToLenientAndNullValue() throws IOException {
Iterator<String> 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");
}
}

0 comments on commit e1cb486

Please sign in to comment.