Skip to content

Commit

Permalink
fix issue 2769
Browse files Browse the repository at this point in the history
  • Loading branch information
IlCommittatore committed Dec 3, 2024
1 parent 84e5f16 commit 6f3eb79
Show file tree
Hide file tree
Showing 2 changed files with 26 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 @@ -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 ';':
Expand Down
25 changes: 25 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,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;

Expand Down Expand Up @@ -2170,6 +2174,27 @@ private static void assertDocument(String document, Object... expectations) thro
}
}

@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");
}

/** Returns a reader that returns one character at a time. */
private static Reader reader(String s) {
/* if (true) */ return new StringReader(s);
Expand Down

0 comments on commit 6f3eb79

Please sign in to comment.