diff --git a/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java index dca1cad29f..4471f21c63 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java @@ -1784,7 +1784,10 @@ protected JsonToken _handleInvalidNumberStart(int ch, final boolean negative, fi if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature()) && hasSign && !negative) { reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } - reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value"); + final String message = negative ? + "expected digit (0-9) to follow minus sign, for valid numeric value" : + "expected digit (0-9) for valid numeric value"; + reportUnexpectedNumberChar(ch, message); return null; } diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java index 1fdc3b363c..7d5f255c85 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java @@ -2273,7 +2273,10 @@ protected JsonToken _handleInvalidNumberStart(int ch, final boolean neg, final b if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature()) && hasSign && !neg) { reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } - reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value"); + final String message = neg ? + "expected digit (0-9) to follow minus sign, for valid numeric value" : + "expected digit (0-9) for valid numeric value"; + reportUnexpectedNumberChar(ch, message); return null; } 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 8a4dafc930..ee7e8a595e 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java @@ -2912,7 +2912,10 @@ protected JsonToken _handleInvalidNumberStart(int ch, final boolean neg, final b if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature()) && hasSign && !neg) { reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } - reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value"); + final String message = neg ? + "expected digit (0-9) to follow minus sign, for valid numeric value" : + "expected digit (0-9) for valid numeric value"; + reportUnexpectedNumberChar(ch, message); return null; } diff --git a/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java index 2e7bfc278c..ac4c904cd8 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java @@ -1730,17 +1730,27 @@ protected JsonToken _finishFloatFraction() throws IOException int outPtr = _textBuffer.getCurrentSegmentSize(); // caller guarantees at least one char; also, sign-extension not needed here - int ch; - while (((ch = _inputBuffer[_inputPtr++]) >= INT_0) && (ch <= INT_9)) { - ++fractLen; - if (outPtr >= outBuf.length) { - outBuf = _textBuffer.expandCurrentSegment(); - } - outBuf[outPtr++] = (char) ch; - if (_inputPtr >= _inputEnd) { - _textBuffer.setCurrentLength(outPtr); - _fractLength = fractLen; - return JsonToken.NOT_AVAILABLE; + int ch = _inputBuffer[_inputPtr++]; + boolean loop = true; + while (loop) { + if (ch >= INT_0 && ch <= INT_9) { + ++fractLen; + if (outPtr >= outBuf.length) { + outBuf = _textBuffer.expandCurrentSegment(); + } + outBuf[outPtr++] = (char) ch; + if (_inputPtr >= _inputEnd) { + _textBuffer.setCurrentLength(outPtr); + _fractLength = fractLen; + return JsonToken.NOT_AVAILABLE; + } + ch = _inputBuffer[_inputPtr++]; + } else if (ch == 'f' || ch == 'd' || ch == 'F' || ch == 'D') { + reportUnexpectedNumberChar(ch, "JSON does not support parsing numbers that have 'f' or 'd' suffixes"); + } else if (ch == INT_PERIOD) { + reportUnexpectedNumberChar(ch, "Cannot parse number with more than one decimal point"); + } else { + loop = false; } } diff --git a/src/test/java/com/fasterxml/jackson/core/json/async/AsyncNonStandardNumberParsingTest.java b/src/test/java/com/fasterxml/jackson/core/json/async/AsyncNonStandardNumberParsingTest.java index 304ac16c0d..bfef6adc8f 100644 --- a/src/test/java/com/fasterxml/jackson/core/json/async/AsyncNonStandardNumberParsingTest.java +++ b/src/test/java/com/fasterxml/jackson/core/json/async/AsyncNonStandardNumberParsingTest.java @@ -62,8 +62,6 @@ public void testNegativeHexadecimal() throws Exception } } - //next 2 tests do not work as expected - /* public void testFloatMarker() throws Exception { final String JSON = "[ -0.123f ]"; @@ -97,7 +95,22 @@ public void testDoubleMarker() throws Exception p.close(); } } - */ + + public void test2DecimalPoints() throws Exception { + final String JSON = "[ -0.123.456 ]"; + + // without enabling, should get an exception + AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1); + assertToken(JsonToken.START_ARRAY, p.nextToken()); + try { + p.nextToken(); + fail("Expected exception"); + } catch (Exception e) { + verifyException(e, "Unexpected character ('.'"); + } finally { + p.close(); + } + } /** * The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail diff --git a/src/test/java/com/fasterxml/jackson/core/read/NonStandardNumberParsingTest.java b/src/test/java/com/fasterxml/jackson/core/read/NonStandardNumberParsingTest.java index d2983fed0c..585f83995a 100644 --- a/src/test/java/com/fasterxml/jackson/core/read/NonStandardNumberParsingTest.java +++ b/src/test/java/com/fasterxml/jackson/core/read/NonStandardNumberParsingTest.java @@ -80,6 +80,17 @@ public void testDoubleMarker() throws Exception { } } + public void test2DecimalPoints() throws Exception { + for (int mode : ALL_MODES) { + try (JsonParser p = createParser(mode, " -0.123.456 ")) { + p.nextToken(); + fail("Should not pass"); + } catch (JsonParseException e) { + verifyException(e, "Unexpected character ('.'"); + } + } + } + /** * The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail */