From 397bc5b1624808b9d036d91d16cccb9e63199878 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 22 Apr 2020 19:46:57 -0700 Subject: [PATCH] some more #611 --- .../core/json/UTF8StreamJsonParser.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java index d6aeae0631..a7faa76f8d 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java @@ -780,6 +780,9 @@ public JsonToken nextToken() 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]: + t = _parseFloatThatStartsWithPeriod(); + break; case '0': case '1': case '2': @@ -845,6 +848,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 indicate by a more specific error message. + case '.': // [core#611]: + return (_currToken = _parseFloatThatStartsWithPeriod()); case '0': case '1': case '2': @@ -1046,6 +1051,9 @@ public String nextFieldName() throws IOException case '-': t = _parseNegNumber(); break; + case '.': // [core#611]: + t = _parseFloatThatStartsWithPeriod(); + break; case '0': case '1': case '2': @@ -1164,6 +1172,9 @@ private final void _isNextTokenNameYes(int i) throws IOException case '-': _nextToken = _parseNegNumber(); return; + case '.': // [core#611]: + _nextToken = _parseFloatThatStartsWithPeriod(); + return; case '0': case '1': case '2': @@ -1221,6 +1232,9 @@ private final boolean _isNextTokenNameMaybe(int i, SerializableString str) throw case '-': t = _parseNegNumber(); break; + case '.': // [core#611]: + t = _parseFloatThatStartsWithPeriod(); + break; case '0': case '1': case '2': @@ -1352,6 +1366,17 @@ 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); + } + return _parseFloat(_textBuffer.emptyAndGetCurrentSegment(), + 0, INT_PERIOD, false, 0); + } + /** * Initial parsing method for number values. It needs to be able * to parse enough input to be able to determine whether the @@ -1538,7 +1563,7 @@ private final int _verifyNoLeadingZeroes() throws IOException } return ch; } - + private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c, boolean negative, int integerPartLength) throws IOException {