@@ -814,9 +814,13 @@ public JsonToken nextToken() throws IOException
814
814
case '-' :
815
815
t = _parseNegNumber ();
816
816
break ;
817
-
818
- // Should we have separate handling for plus? Although it is not allowed per se,
819
- // it may be erroneously used, and could be indicate by a more specific error message.
817
+ case '+' :
818
+ if (!isEnabled (JsonReadFeature .ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS .mappedFeature ())) {
819
+ t = _handleUnexpectedValue (i );
820
+ } else {
821
+ t = _parsePosNumber ();
822
+ }
823
+ break ;
820
824
case '.' : // [core#611]:
821
825
t = _parseFloatThatStartsWithPeriod ();
822
826
break ;
@@ -882,9 +886,11 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
882
886
return (_currToken = JsonToken .VALUE_NULL );
883
887
case '-' :
884
888
return (_currToken = _parseNegNumber ());
885
-
886
- // Should we have separate handling for plus? Although it is not allowed per se,
887
- // it may be erroneously used, and could be indicate by a more specific error message.
889
+ case '+' :
890
+ if (!isEnabled (JsonReadFeature .ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS .mappedFeature ())) {
891
+ return (_currToken = _handleUnexpectedValue (i ));
892
+ }
893
+ return (_currToken = _parsePosNumber ());
888
894
case '.' : // [core#611]:
889
895
return (_currToken = _parseFloatThatStartsWithPeriod ());
890
896
case '0' :
@@ -1475,14 +1481,26 @@ protected JsonToken _parsePosNumber(int c) throws IOException
1475
1481
// And there we have it!
1476
1482
return resetInt (false , intLen );
1477
1483
}
1478
-
1484
+
1485
+ protected JsonToken _parsePosNumber () throws IOException
1486
+ {
1487
+ return _parsePossibleNumber (false );
1488
+ }
1489
+
1479
1490
protected JsonToken _parseNegNumber () throws IOException
1491
+ {
1492
+ return _parsePossibleNumber (true );
1493
+ }
1494
+
1495
+ private JsonToken _parsePossibleNumber (boolean negative ) throws IOException
1480
1496
{
1481
1497
char [] outBuf = _textBuffer .emptyAndGetCurrentSegment ();
1482
1498
int outPtr = 0 ;
1483
1499
1484
- // Need to prepend sign?
1485
- outBuf [outPtr ++] = '-' ;
1500
+ if (negative ) {
1501
+ // Need to prepend sign?
1502
+ outBuf [outPtr ++] = '-' ;
1503
+ }
1486
1504
// Must have something after sign too
1487
1505
if (_inputPtr >= _inputEnd ) {
1488
1506
_loadMoreGuaranteed ();
@@ -1492,13 +1510,16 @@ protected JsonToken _parseNegNumber() throws IOException
1492
1510
if (c <= INT_0 ) {
1493
1511
// One special case: if first char is 0, must not be followed by a digit
1494
1512
if (c != INT_0 ) {
1495
- return _handleInvalidNumberStart (c , true );
1513
+ if (c == INT_PERIOD ) {
1514
+ return _parseFloatThatStartsWithPeriod ();
1515
+ }
1516
+ return _handleInvalidNumberStart (c , negative );
1496
1517
}
1497
1518
c = _verifyNoLeadingZeroes ();
1498
1519
} else if (c > INT_9 ) {
1499
- return _handleInvalidNumberStart (c , true );
1520
+ return _handleInvalidNumberStart (c , negative );
1500
1521
}
1501
-
1522
+
1502
1523
// Ok: we can first just add digit we saw first:
1503
1524
outBuf [outPtr ++] = (char ) c ;
1504
1525
int intLen = 1 ;
@@ -1510,7 +1531,7 @@ protected JsonToken _parseNegNumber() throws IOException
1510
1531
while (true ) {
1511
1532
if (_inputPtr >= end ) {
1512
1533
// Long enough to be split across boundary, so:
1513
- return _parseNumber2 (outBuf , outPtr , true , intLen );
1534
+ return _parseNumber2 (outBuf , outPtr , negative , intLen );
1514
1535
}
1515
1536
c = (int ) _inputBuffer [_inputPtr ++] & 0xFF ;
1516
1537
if (c < INT_0 || c > INT_9 ) {
@@ -1520,9 +1541,9 @@ protected JsonToken _parseNegNumber() throws IOException
1520
1541
outBuf [outPtr ++] = (char ) c ;
1521
1542
}
1522
1543
if (c == INT_PERIOD || c == INT_e || c == INT_E ) {
1523
- return _parseFloat (outBuf , outPtr , c , true , intLen );
1544
+ return _parseFloat (outBuf , outPtr , c , negative , intLen );
1524
1545
}
1525
-
1546
+
1526
1547
--_inputPtr ; // to push back trailing char (comma etc)
1527
1548
_textBuffer .setCurrentLength (outPtr );
1528
1549
// As per #105, need separating space between root values; check here
@@ -1531,7 +1552,7 @@ protected JsonToken _parseNegNumber() throws IOException
1531
1552
}
1532
1553
1533
1554
// And there we have it!
1534
- return resetInt (true , intLen );
1555
+ return resetInt (negative , intLen );
1535
1556
}
1536
1557
1537
1558
// Method called to handle parsing when input is split across buffer boundary
0 commit comments