Skip to content

Commit 07d21c2

Browse files
committed
#115 better leading zero detection
1 parent 975242c commit 07d21c2

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/main/java/com/jsoniter/IterImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ public static int updateStringCopyBound(final JsonIterator iter, final int bound
308308
static final int readPositiveInt(final JsonIterator iter, byte c) throws IOException {
309309
int ind = IterImplNumber.intDigits[c];
310310
if (ind == 0) {
311-
return 0;
311+
throw iter.reportError("readPositiveInt", "leading zero is invalid for int");
312312
}
313313
if (ind == IterImplNumber.INVALID_CHAR_FOR_NUMBER) {
314-
throw iter.reportError("readPositiveInt", "expect 0~9");
314+
throw iter.reportError("readPositiveInt", "expect 1~9");
315315
}
316316
if (iter.tail - iter.head > 9) {
317317
int i = iter.head;
@@ -362,8 +362,11 @@ static final int readPositiveInt(final JsonIterator iter, byte c) throws IOExcep
362362

363363
static final long readPositiveLong(final JsonIterator iter, byte c) throws IOException {
364364
long ind = IterImplNumber.intDigits[c];
365+
if (ind == 0) {
366+
throw iter.reportError("readPositiveLong", "leading zero is invalid for long");
367+
}
365368
if (ind == IterImplNumber.INVALID_CHAR_FOR_NUMBER) {
366-
throw iter.reportError("readPositiveLong", "expect 0~9");
369+
throw iter.reportError("readPositiveLong", "expect 1~9");
367370
}
368371
if (iter.tail - iter.head > 9) {
369372
int i = iter.head;

src/main/java/com/jsoniter/IterImplNumber.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ public static final int readInt(final JsonIterator iter) throws IOException {
8787
byte c = IterImpl.nextToken(iter);
8888
if (c == '-') {
8989
return -IterImpl.readPositiveInt(iter, IterImpl.readByte(iter));
90-
} else if (c == '0') {
91-
throw new JsonException("leading zero is invalid number");
9290
} else {
9391
return IterImpl.readPositiveInt(iter, c);
9492
}
@@ -98,8 +96,6 @@ public static final long readLong(JsonIterator iter) throws IOException {
9896
byte c = IterImpl.nextToken(iter);
9997
if (c == '-') {
10098
return -IterImpl.readPositiveLong(iter, IterImpl.readByte(iter));
101-
} else if (c == '0') {
102-
throw new JsonException("leading zero is invalid number");
10399
} else {
104100
return IterImpl.readPositiveLong(iter, c);
105101
}

0 commit comments

Comments
 (0)