Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9cc36df

Browse files
committed
more #611
1 parent c3a9b5e commit 9cc36df

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,12 @@ public JsonToken nextToken() throws IOException
656656
t = _parseNegNumber();
657657
break;
658658

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;
663665
case '0':
664666
case '1':
665667
case '2':
@@ -670,7 +672,6 @@ public JsonToken nextToken() throws IOException
670672
case '7':
671673
case '8':
672674
case '9':
673-
case '.': // as per [core#611]
674675
t = _parsePosNumber(i);
675676
break;
676677
case 'f':
@@ -726,6 +727,8 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
726727
// Should we have separate handling for plus? Although it is not allowed
727728
// per se, it may be erroneously used, and could be indicated by a more
728729
// specific error message.
730+
case '.': // as per [core#611]
731+
return (_currToken = _parseFloatThatStartsWithPeriod());
729732
case '0':
730733
case '1':
731734
case '2':
@@ -736,7 +739,6 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
736739
case '7':
737740
case '8':
738741
case '9':
739-
case '.': // as per [core#611]
740742
return (_currToken = _parsePosNumber(i));
741743
}
742744
return (_currToken = _handleUnexpectedValue(i));
@@ -832,6 +834,8 @@ public String nextFieldName() throws IOException
832834
case '-':
833835
t = _parseNegNumber();
834836
break;
837+
case '.': // as per [core#611]
838+
t = _parseFloatThatStartsWithPeriod();
835839
case '0':
836840
case '1':
837841
case '2':
@@ -842,7 +846,6 @@ public String nextFieldName() throws IOException
842846
case '7':
843847
case '8':
844848
case '9':
845-
case '.': // as per [core#611]
846849
t = _parsePosNumber(i);
847850
break;
848851
case 'f':
@@ -980,6 +983,20 @@ public Boolean nextBooleanValue() throws IOException
980983
/**********************************************************
981984
*/
982985

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+
9831000
/**
9841001
* Initial parsing method for number values. It needs to be able
9851002
* to parse enough input to be able to determine whether the
@@ -999,7 +1016,6 @@ protected JsonToken _parsePosNumber(int c) throws IOException
9991016
{
10001017
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
10011018
int outPtr;
1002-
final boolean forceFloat;
10031019

10041020
// One special case: if first char is 0, must not be followed by a digit.
10051021
// 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
10111027
outBuf[0] = '0';
10121028
outPtr = 1;
10131029
}
1014-
forceFloat = false;
10151030
} 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-
10241031
outBuf[0] = (char) c;
10251032
c = _inputData.readUnsignedByte();
10261033
outPtr = 1;
@@ -1037,7 +1044,7 @@ protected JsonToken _parsePosNumber(int c) throws IOException
10371044
outBuf[outPtr++] = (char) c;
10381045
c = _inputData.readUnsignedByte();
10391046
}
1040-
if (c == '.' || c == 'e' || c == 'E' || forceFloat) {
1047+
if (c == '.' || c == 'e' || c == 'E') {
10411048
return _parseFloat(outBuf, outPtr, c, false, intLen);
10421049
}
10431050
_textBuffer.setCurrentLength(outPtr);

0 commit comments

Comments
 (0)