Skip to content

Commit ba73426

Browse files
committed
Fixed parsing zero when streaming is enabled.
1 parent 2a575f8 commit ba73426

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Diff for: src/main/java/com/jsoniter/IterImplForStreaming.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,7 @@ static final int readInt(final JsonIterator iter, final byte c) throws IOExcepti
649649

650650
static void assertNotLeadingZero(JsonIterator iter) throws IOException {
651651
try {
652-
byte nextByte = IterImpl.readByte(iter);
653-
iter.unreadByte();
652+
byte nextByte = iter.buf[iter.head];
654653
int ind2 = IterImplNumber.intDigits[nextByte];
655654
if (ind2 == IterImplNumber.INVALID_CHAR_FOR_NUMBER) {
656655
return;

Diff for: src/test/java/com/jsoniter/any/TestLong.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
package com.jsoniter.any;
22

3+
import com.jsoniter.spi.JsonException;
34
import junit.framework.TestCase;
45

56
public class TestLong extends TestCase {
67
public void test_to_string_should_trim() {
78
Any any = Any.lazyLong(" 1000".getBytes(), 0, " 1000".length());
89
assertEquals("1000", any.toString());
910
}
11+
12+
public void test_should_fail_with_leading_zero() {
13+
byte[] bytes = "01".getBytes();
14+
Any any = Any.lazyLong(bytes, 0, bytes.length);
15+
try {
16+
any.toLong();
17+
fail("This should fail.");
18+
} catch (JsonException e) {
19+
20+
}
21+
}
22+
23+
public void test_should_work_with_zero() {
24+
byte[] bytes = "0".getBytes();
25+
Any any = Any.lazyLong(bytes, 0, bytes.length);
26+
assertEquals(0L, any.toLong());
27+
}
1028
}

0 commit comments

Comments
 (0)