Skip to content

Commit c1920ed

Browse files
committed
More work for #611: only thing missing, verifying async parser
1 parent 397bc5b commit c1920ed

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,7 @@ Michel Feinstein (feinstein@github)
231231
Oleksandr Poslavskyi (alevskyi@github)
232232
* Contributed implementation of #504: Add a String Array write method in the Streaming API
233233
(2.11.0)
234+
235+
James Agnew (jamesagnew@github)
236+
* Contributed implementation of #611: Optionally allow leading decimal in float tokens
237+
(2.11.0)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ JSON library.
2525
#606: Do not clear aggregated contents of `TextBuffer` when `releaseBuffers()` called
2626
#609: `FilteringGeneratorDelegate` does not handle `writeString(Reader, int)`
2727
(reported by Volkan Y)
28+
#611: Optionally allow leading decimal in float tokens
29+
(contributed by James A)
2830

2931
2.10.4 (not yet released)
3032

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,6 @@ public Boolean nextBooleanValue() throws IOException
983983
/**********************************************************
984984
*/
985985

986-
987986
// @since 2.11, [core#611]
988987
protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException
989988
{
@@ -992,9 +991,7 @@ protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException
992991
return _handleUnexpectedValue(INT_PERIOD);
993992
}
994993
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
995-
outBuf[0] = '.';
996-
int c = _inputData.readUnsignedByte();
997-
return _parseFloat(outBuf, 1, c, false, 0);
994+
return _parseFloat(outBuf, 0, INT_PERIOD, false, 0);
998995
}
999996

1000997
/**

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fasterxml.jackson.core.async.NonBlockingInputFeeder;
99
import com.fasterxml.jackson.core.io.CharTypes;
1010
import com.fasterxml.jackson.core.io.IOContext;
11+
import com.fasterxml.jackson.core.json.JsonReadFeature;
1112
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
1213
import com.fasterxml.jackson.core.util.VersionUtil;
1314

@@ -625,6 +626,13 @@ private final JsonToken _startValue(int ch) throws IOException
625626
// Should we have separate handling for plus? Although
626627
// it is not allowed per se, it may be erroneously used,
627628
// and could be indicate by a more specific error message.
629+
630+
case '.': // [core#611]
631+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) {
632+
return _startFloatThatStartsWithPeriod();
633+
}
634+
break;
635+
628636
case '0':
629637
return _startNumberLeadingZero();
630638
case '1':
@@ -1286,6 +1294,15 @@ protected JsonToken _reportErrorToken(String actualToken) throws IOException
12861294
/**********************************************************************
12871295
*/
12881296

1297+
// [core#611]: allow non-standard floats like ".125"
1298+
protected JsonToken _startFloatThatStartsWithPeriod() throws IOException
1299+
{
1300+
_numberNegative = false;
1301+
_intLength = 0;
1302+
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
1303+
return _startFloat(outBuf, 0, INT_PERIOD);
1304+
}
1305+
12891306
protected JsonToken _startPositiveNumber(int ch) throws IOException
12901307
{
12911308
_numberNegative = false;

src/test/java/com/fasterxml/jackson/failing/NonStandardNumbers611Test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
public class NonStandardNumbers611Test
77
extends com.fasterxml.jackson.core.BaseTest
88
{
9+
private final JsonFactory JSON_F = JsonFactory.builder()
10+
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
11+
.build();
12+
913
/**
1014
* The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail
1115
*/
@@ -22,10 +26,6 @@ public void testLeadingDotInDecimal() throws Exception {
2226
}
2327
}
2428

25-
private final JsonFactory JSON_F = JsonFactory.builder()
26-
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
27-
.build();
28-
2929
public void testLeadingDotInDecimalAllowedAsync() throws Exception {
3030
_testLeadingDotInDecimalAllowed(JSON_F, MODE_DATA_INPUT);
3131
}

0 commit comments

Comments
 (0)