Skip to content

Commit

Permalink
More work for #611: only thing missing, verifying async parser
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 23, 2020
1 parent 397bc5b commit c1920ed
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Expand Up @@ -231,3 +231,7 @@ Michel Feinstein (feinstein@github)
Oleksandr Poslavskyi (alevskyi@github)
* Contributed implementation of #504: Add a String Array write method in the Streaming API
(2.11.0)
James Agnew (jamesagnew@github)
* Contributed implementation of #611: Optionally allow leading decimal in float tokens
(2.11.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Expand Up @@ -25,6 +25,8 @@ JSON library.
#606: Do not clear aggregated contents of `TextBuffer` when `releaseBuffers()` called
#609: `FilteringGeneratorDelegate` does not handle `writeString(Reader, int)`
(reported by Volkan Y)
#611: Optionally allow leading decimal in float tokens
(contributed by James A)

2.10.4 (not yet released)

Expand Down
Expand Up @@ -983,7 +983,6 @@ public Boolean nextBooleanValue() throws IOException
/**********************************************************
*/


// @since 2.11, [core#611]
protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException
{
Expand All @@ -992,9 +991,7 @@ protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException
return _handleUnexpectedValue(INT_PERIOD);
}
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
outBuf[0] = '.';
int c = _inputData.readUnsignedByte();
return _parseFloat(outBuf, 1, c, false, 0);
return _parseFloat(outBuf, 0, INT_PERIOD, false, 0);
}

/**
Expand Down
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.core.async.NonBlockingInputFeeder;
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
import com.fasterxml.jackson.core.util.VersionUtil;

Expand Down Expand Up @@ -625,6 +626,13 @@ private final JsonToken _startValue(int ch) throws IOException
// 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 '.': // [core#611]
if (isEnabled(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) {
return _startFloatThatStartsWithPeriod();
}
break;

case '0':
return _startNumberLeadingZero();
case '1':
Expand Down Expand Up @@ -1286,6 +1294,15 @@ protected JsonToken _reportErrorToken(String actualToken) throws IOException
/**********************************************************************
*/

// [core#611]: allow non-standard floats like ".125"
protected JsonToken _startFloatThatStartsWithPeriod() throws IOException
{
_numberNegative = false;
_intLength = 0;
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
return _startFloat(outBuf, 0, INT_PERIOD);
}

protected JsonToken _startPositiveNumber(int ch) throws IOException
{
_numberNegative = false;
Expand Down
Expand Up @@ -6,6 +6,10 @@
public class NonStandardNumbers611Test
extends com.fasterxml.jackson.core.BaseTest
{
private final JsonFactory JSON_F = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
.build();

/**
* The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail
*/
Expand All @@ -22,10 +26,6 @@ public void testLeadingDotInDecimal() throws Exception {
}
}

private final JsonFactory JSON_F = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
.build();

public void testLeadingDotInDecimalAllowedAsync() throws Exception {
_testLeadingDotInDecimalAllowed(JSON_F, MODE_DATA_INPUT);
}
Expand Down

0 comments on commit c1920ed

Please sign in to comment.