Skip to content

Commit

Permalink
more #611
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 23, 2020
1 parent c3a9b5e commit 9cc36df
Showing 1 changed file with 25 additions and 18 deletions.
Expand Up @@ -656,10 +656,12 @@ public JsonToken nextToken() throws IOException
t = _parseNegNumber();
break;

/* Should we have separate handling for plus? Although
* it is not allowed per se, it may be erroneously used,
* and could be indicate by a more specific error message.
*/
// Should we have separate handling for plus? Although
// it is not allowed per se, it may be erroneously used,
// and could be indicate by a more specific error message.
case '.': // as per [core#611]
t = _parseFloatThatStartsWithPeriod();
break;
case '0':
case '1':
case '2':
Expand All @@ -670,7 +672,6 @@ public JsonToken nextToken() throws IOException
case '7':
case '8':
case '9':
case '.': // as per [core#611]
t = _parsePosNumber(i);
break;
case 'f':
Expand Down Expand Up @@ -726,6 +727,8 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
// Should we have separate handling for plus? Although it is not allowed
// per se, it may be erroneously used, and could be indicated by a more
// specific error message.
case '.': // as per [core#611]
return (_currToken = _parseFloatThatStartsWithPeriod());
case '0':
case '1':
case '2':
Expand All @@ -736,7 +739,6 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
case '7':
case '8':
case '9':
case '.': // as per [core#611]
return (_currToken = _parsePosNumber(i));
}
return (_currToken = _handleUnexpectedValue(i));
Expand Down Expand Up @@ -832,6 +834,8 @@ public String nextFieldName() throws IOException
case '-':
t = _parseNegNumber();
break;
case '.': // as per [core#611]
t = _parseFloatThatStartsWithPeriod();
case '0':
case '1':
case '2':
Expand All @@ -842,7 +846,6 @@ public String nextFieldName() throws IOException
case '7':
case '8':
case '9':
case '.': // as per [core#611]
t = _parsePosNumber(i);
break;
case 'f':
Expand Down Expand Up @@ -980,6 +983,20 @@ public Boolean nextBooleanValue() throws IOException
/**********************************************************
*/


// @since 2.11, [core#611]
protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException
{
// [core#611]: allow optionally leading decimal point
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) {
return _handleUnexpectedValue(INT_PERIOD);
}
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
outBuf[0] = '.';
int c = _inputData.readUnsignedByte();
return _parseFloat(outBuf, 1, c, false, 0);
}

/**
* Initial parsing method for number values. It needs to be able
* to parse enough input to be able to determine whether the
Expand All @@ -999,7 +1016,6 @@ protected JsonToken _parsePosNumber(int c) throws IOException
{
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
int outPtr;
final boolean forceFloat;

// One special case: if first char is 0, must not be followed by a digit.
// Gets bit tricky as we only want to retain 0 if it's the full value
Expand All @@ -1011,16 +1027,7 @@ protected JsonToken _parsePosNumber(int c) throws IOException
outBuf[0] = '0';
outPtr = 1;
}
forceFloat = false;
} else {
forceFloat = (c == INT_PERIOD);
if (forceFloat) {
// [core#611]: allow optionally leading decimal point
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) {
return _handleUnexpectedValue(c);
}
}

outBuf[0] = (char) c;
c = _inputData.readUnsignedByte();
outPtr = 1;
Expand All @@ -1037,7 +1044,7 @@ protected JsonToken _parsePosNumber(int c) throws IOException
outBuf[outPtr++] = (char) c;
c = _inputData.readUnsignedByte();
}
if (c == '.' || c == 'e' || c == 'E' || forceFloat) {
if (c == '.' || c == 'e' || c == 'E') {
return _parseFloat(outBuf, outPtr, c, false, intLen);
}
_textBuffer.setCurrentLength(outPtr);
Expand Down

0 comments on commit 9cc36df

Please sign in to comment.