@@ -656,10 +656,12 @@ public JsonToken nextToken() throws IOException
656
656
t = _parseNegNumber ();
657
657
break ;
658
658
659
- /* Should we have separate handling for plus? Although
660
- * it is not allowed per se, it may be erroneously used,
661
- * and could be indicate by a more specific error message.
662
- */
659
+ // Should we have separate handling for plus? Although
660
+ // it is not allowed per se, it may be erroneously used,
661
+ // and could be indicate by a more specific error message.
662
+ case '.' : // as per [core#611]
663
+ t = _parseFloatThatStartsWithPeriod ();
664
+ break ;
663
665
case '0' :
664
666
case '1' :
665
667
case '2' :
@@ -670,7 +672,6 @@ public JsonToken nextToken() throws IOException
670
672
case '7' :
671
673
case '8' :
672
674
case '9' :
673
- case '.' : // as per [core#611]
674
675
t = _parsePosNumber (i );
675
676
break ;
676
677
case 'f' :
@@ -726,6 +727,8 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
726
727
// Should we have separate handling for plus? Although it is not allowed
727
728
// per se, it may be erroneously used, and could be indicated by a more
728
729
// specific error message.
730
+ case '.' : // as per [core#611]
731
+ return (_currToken = _parseFloatThatStartsWithPeriod ());
729
732
case '0' :
730
733
case '1' :
731
734
case '2' :
@@ -736,7 +739,6 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
736
739
case '7' :
737
740
case '8' :
738
741
case '9' :
739
- case '.' : // as per [core#611]
740
742
return (_currToken = _parsePosNumber (i ));
741
743
}
742
744
return (_currToken = _handleUnexpectedValue (i ));
@@ -832,6 +834,8 @@ public String nextFieldName() throws IOException
832
834
case '-' :
833
835
t = _parseNegNumber ();
834
836
break ;
837
+ case '.' : // as per [core#611]
838
+ t = _parseFloatThatStartsWithPeriod ();
835
839
case '0' :
836
840
case '1' :
837
841
case '2' :
@@ -842,7 +846,6 @@ public String nextFieldName() throws IOException
842
846
case '7' :
843
847
case '8' :
844
848
case '9' :
845
- case '.' : // as per [core#611]
846
849
t = _parsePosNumber (i );
847
850
break ;
848
851
case 'f' :
@@ -980,6 +983,20 @@ public Boolean nextBooleanValue() throws IOException
980
983
/**********************************************************
981
984
*/
982
985
986
+
987
+ // @since 2.11, [core#611]
988
+ protected final JsonToken _parseFloatThatStartsWithPeriod () throws IOException
989
+ {
990
+ // [core#611]: allow optionally leading decimal point
991
+ if (!isEnabled (JsonReadFeature .ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS .mappedFeature ())) {
992
+ return _handleUnexpectedValue (INT_PERIOD );
993
+ }
994
+ char [] outBuf = _textBuffer .emptyAndGetCurrentSegment ();
995
+ outBuf [0 ] = '.' ;
996
+ int c = _inputData .readUnsignedByte ();
997
+ return _parseFloat (outBuf , 1 , c , false , 0 );
998
+ }
999
+
983
1000
/**
984
1001
* Initial parsing method for number values. It needs to be able
985
1002
* to parse enough input to be able to determine whether the
@@ -999,7 +1016,6 @@ protected JsonToken _parsePosNumber(int c) throws IOException
999
1016
{
1000
1017
char [] outBuf = _textBuffer .emptyAndGetCurrentSegment ();
1001
1018
int outPtr ;
1002
- final boolean forceFloat ;
1003
1019
1004
1020
// One special case: if first char is 0, must not be followed by a digit.
1005
1021
// Gets bit tricky as we only want to retain 0 if it's the full value
@@ -1011,16 +1027,7 @@ protected JsonToken _parsePosNumber(int c) throws IOException
1011
1027
outBuf [0 ] = '0' ;
1012
1028
outPtr = 1 ;
1013
1029
}
1014
- forceFloat = false ;
1015
1030
} else {
1016
- forceFloat = (c == INT_PERIOD );
1017
- if (forceFloat ) {
1018
- // [core#611]: allow optionally leading decimal point
1019
- if (!isEnabled (JsonReadFeature .ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS .mappedFeature ())) {
1020
- return _handleUnexpectedValue (c );
1021
- }
1022
- }
1023
-
1024
1031
outBuf [0 ] = (char ) c ;
1025
1032
c = _inputData .readUnsignedByte ();
1026
1033
outPtr = 1 ;
@@ -1037,7 +1044,7 @@ protected JsonToken _parsePosNumber(int c) throws IOException
1037
1044
outBuf [outPtr ++] = (char ) c ;
1038
1045
c = _inputData .readUnsignedByte ();
1039
1046
}
1040
- if (c == '.' || c == 'e' || c == 'E' || forceFloat ) {
1047
+ if (c == '.' || c == 'e' || c == 'E' ) {
1041
1048
return _parseFloat (outBuf , outPtr , c , false , intLen );
1042
1049
}
1043
1050
_textBuffer .setCurrentLength (outPtr );
0 commit comments