File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3131 */
3232package com .jsoniter ;
3333
34+ import com .jsoniter .spi .JsonException ;
35+
3436import java .io .IOException ;
3537
3638class IterImplNumber {
@@ -85,6 +87,8 @@ public static final int readInt(final JsonIterator iter) throws IOException {
8587 byte c = IterImpl .nextToken (iter );
8688 if (c == '-' ) {
8789 return -IterImpl .readPositiveInt (iter , IterImpl .readByte (iter ));
90+ } else if (c == '0' ) {
91+ throw new JsonException ("leading zero is invalid number" );
8892 } else {
8993 return IterImpl .readPositiveInt (iter , c );
9094 }
@@ -94,6 +98,8 @@ public static final long readLong(JsonIterator iter) throws IOException {
9498 byte c = IterImpl .nextToken (iter );
9599 if (c == '-' ) {
96100 return -IterImpl .readPositiveLong (iter , IterImpl .readByte (iter ));
101+ } else if (c == '0' ) {
102+ throw new JsonException ("leading zero is invalid number" );
97103 } else {
98104 return IterImpl .readPositiveLong (iter , c );
99105 }
Original file line number Diff line number Diff line change @@ -92,6 +92,16 @@ public void test_leading_zero() throws IOException {
9292 fail ();
9393 } catch (JsonException e ) {
9494 }
95+ try {
96+ JsonIterator .deserialize ("001" , long .class );
97+ fail ();
98+ } catch (JsonException e ) {
99+ }
100+ try {
101+ JsonIterator .deserialize ("001" );
102+ fail ();
103+ } catch (JsonException e ) {
104+ }
95105 }
96106
97107 public void test_max_int () throws IOException {
You can’t perform that action at this time.
0 commit comments