Skip to content

Commit 692b7b5

Browse files
committed
fix readStringAsSlice in streaming mode
1 parent 208778a commit 692b7b5

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

demo/src/test/java/com/jsoniter/demo/ReadString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void test() throws IOException {
3434
@Setup(Level.Trial)
3535
public void benchSetup(BenchmarkParams params) {
3636
jsonIterator = new JsonIterator();
37-
input = "\"hello wo\\trld\"".getBytes();
37+
input = "\"hello world\"".getBytes();
3838
}
3939

4040
@Benchmark

src/main/java/com/jsoniter/IterImplForStreaming.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ final static boolean skipNumber(JsonIterator iter) throws IOException {
195195

196196
// read the bytes between " "
197197
final static Slice readSlice(JsonIterator iter) throws IOException {
198+
if (IterImpl.nextToken(iter) != '"') {
199+
throw iter.reportError("readSlice", "expect \" for string");
200+
}
198201
int end = IterImplString.findSliceEnd(iter);
199202
if (end != -1) {
200203
// reuse current buffer

src/test/java/com/jsoniter/TestString.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public void test_ascii_string() throws IOException {
1717
assertEquals("hello", iter.readString());
1818
assertEquals("world", iter.readString());
1919
iter = JsonIterator.parse("'hello''world'".replace('\'', '"'));
20-
assertEquals("hello", iter.readString());
21-
assertEquals("world", iter.readString());
20+
assertEquals("hello", iter.readStringAsSlice().toString());
21+
assertEquals("world", iter.readStringAsSlice().toString());
2222
}
2323

2424
public void test_ascii_string_with_escape() throws IOException {
@@ -55,6 +55,9 @@ public void test_string_across_buffer() throws IOException {
5555
JsonIterator iter = JsonIterator.parse(new ByteArrayInputStream("'hello''world'".replace('\'', '"').getBytes()), 2);
5656
assertEquals("hello", iter.readString());
5757
assertEquals("world", iter.readString());
58+
iter = JsonIterator.parse(new ByteArrayInputStream("'hello''world'".replace('\'', '"').getBytes()), 2);
59+
assertEquals("hello", iter.readStringAsSlice().toString());
60+
assertEquals("world", iter.readStringAsSlice().toString());
5861
}
5962

6063
@org.junit.experimental.categories.Category(StreamingCategory.class)

0 commit comments

Comments
 (0)