From 1ae30da82b9824211fc304d4d505e73a659cda6e Mon Sep 17 00:00:00 2001 From: seonwooj0810 Date: Fri, 29 May 2026 09:43:39 +0900 Subject: [PATCH] Fix #1557: eagerly validate separator after non-root number values Number values inside Arrays/Objects were only checked for a valid trailing separator at root level (cf. #105 / #679). Non-root values pushed the trailing character back unchecked, so malformed input such as `[ 123true ]`, `[ 100k ]` or `[ 1.5x ]` reported a number token and only failed lazily when accessing the *following* token. Generalize the existing root-only `_verifyRootSpace` into `_verifyNumberSeparator`, applied at every number-completion site in the three blocking parsers (Reader / UTF-8 stream / UTF-8 DataInput). A non-root number must now be followed by white space, `,`, `]`, `}`, a comment start (when comments are enabled) or end-of-input; otherwise an "expected space..." error is reported at the offending character. The check reuses the trailing character already read to detect the end of the number and is a constant-time switch, so the hot path cost is negligible. Tests: add non-root verification (and comment-adjacent cases) to `NonStandardNumberParsingTest` across ALL_MODES; remove the now-fixed `tofix` repros for the blocking parsers. Async (non-blocking) parser is intentionally left as a follow-up; its `tofix` repro remains under `@JacksonTestFailureExpected`. --- release-notes/VERSION | 2 + .../core/json/ReaderBasedJsonParser.java | 72 +++++++++--- .../core/json/UTF8DataInputJsonParser.java | 69 +++++++++--- .../core/json/UTF8StreamJsonParser.java | 76 +++++++++---- src/test/java/module-info.java | 1 - .../read/NonStandardNumberParsingTest.java | 62 +++++++++++ .../tofix/ParserErrorHandling1557Test.java | 103 ------------------ .../ParserErrorHandlingBytes1557Test.java | 57 ---------- .../ParserErrorHandlingChars1557Test.java | 55 ---------- .../ParserErrorHandlingDataInput1557Test.java | 57 ---------- 10 files changed, 230 insertions(+), 324 deletions(-) delete mode 100644 src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandling1557Test.java delete mode 100644 src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingBytes1557Test.java delete mode 100644 src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingChars1557Test.java delete mode 100644 src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingDataInput1557Test.java diff --git a/release-notes/VERSION b/release-notes/VERSION index eba3be08a8..1e320e7cc9 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -28,6 +28,8 @@ JSON library. #1544: Validate `read()` parameters in `MergedStream` and `UTF32Reader` (implemented by @pjfanning) #1545: Increase Android baseline from 26 to 34 in Jackson 3.2 +#1557: Parsing for non-root number values fails lazily + (fix for blocking parsers by @seonwooj0810) #1564: Add `SimpleStreamReadContext.rollbackValueRead()` method #1575: Implement document length tracking for `DataInput`-backed JSON parsers via subclass diff --git a/src/main/java/tools/jackson/core/json/ReaderBasedJsonParser.java b/src/main/java/tools/jackson/core/json/ReaderBasedJsonParser.java index 94cf2320de..44ae30f84b 100644 --- a/src/main/java/tools/jackson/core/json/ReaderBasedJsonParser.java +++ b/src/main/java/tools/jackson/core/json/ReaderBasedJsonParser.java @@ -1413,10 +1413,8 @@ protected final JsonToken _parseUnsignedNumber(int ch) throws JacksonException // Got it all: let's add to text buffer for parsing, access --ptr; // need to push back following separator _inputPtr = ptr; - // As per #105, need separating space between root values; check here - if (_streamReadContext.inRoot()) { - _verifyRootSpace(ch); - } + // [core#105]/[core#1557]: verify number is properly terminated/separated + _verifyNumberSeparator(ch); int len = ptr-startPtr; _textBuffer.resetWithShared(_inputBuffer, startPtr, len); return resetInt(false, intLen); @@ -1480,10 +1478,8 @@ private final JsonToken _parseFloat(int ch, int startPtr, int ptr, boolean neg, } --ptr; // need to push back following separator _inputPtr = ptr; - // As per #105, need separating space between root values; check here - if (_streamReadContext.inRoot()) { - _verifyRootSpace(ch); - } + // [core#105]/[core#1557]: verify number is properly terminated/separated + _verifyNumberSeparator(ch); int len = ptr-startPtr; _textBuffer.resetWithShared(_inputBuffer, startPtr, len); // And there we have it! @@ -1538,9 +1534,7 @@ private final JsonToken _parseSignedNumber(final boolean negative) throws Jackso } --ptr; _inputPtr = ptr; - if (_streamReadContext.inRoot()) { - _verifyRootSpace(ch); - } + _verifyNumberSeparator(ch); int len = ptr-startPtr; _textBuffer.resetWithShared(_inputBuffer, startPtr, len); return resetInt(negative, intLen); @@ -1704,9 +1698,7 @@ private final JsonToken _parseNumber2(boolean neg, int startPtr) throws JacksonE // Ok; unless we hit end-of-input, need to push last char read back if (!eof) { --_inputPtr; - if (_streamReadContext.inRoot()) { - _verifyRootSpace(c); - } + _verifyNumberSeparator(c); } _textBuffer.setCurrentLength(outPtr); @@ -1773,9 +1765,7 @@ private final JsonToken _finishHexNumber(boolean neg, if (!eof) { --_inputPtr; // push back the terminating non-hex char - if (_streamReadContext.inRoot()) { - _verifyRootSpace(c); - } + _verifyNumberSeparator(c); } _textBuffer.setCurrentLength(outPtr); return resetIntHex(neg, hexLen); @@ -1907,6 +1897,54 @@ private final void _verifyRootSpace(int ch) throws JacksonException _reportMissingRootWS(ch); } + /** + * Method called to verify that a just-decoded number value is followed by a + * valid separator or terminator character. For root-level values this means + * white space (as per [core#105], see {@link #_verifyRootSpace}); for non-root + * values ([core#1557]) the number must be followed by white space, a value + * separator ({@code ','}), an enclosing-structure end ({@code ']'} or + * {@code '}'}), a comment start (when enabled) or end-of-input. Without this, + * malformed content such as {@code [ 123true ]} would only fail lazily when + * accessing the following token. + *

+ * On entry the caller has pushed the trailing character back, so {@code _inputPtr} + * points at it; for accepted separators this method leaves {@code _inputPtr} + * untouched so the next {@code nextToken()} call can consume them normally. + */ + private final void _verifyNumberSeparator(int ch) throws JacksonException + { + if (_streamReadContext.inRoot()) { + _verifyRootSpace(ch); + return; + } + switch (ch) { + case ' ': + case '\t': + case '\n': + case '\r': + case ',': + case ']': + case '}': + return; + case '/': // possible Java/C++ style comment + if (isEnabled(JsonReadFeature.ALLOW_JAVA_COMMENTS)) { + return; + } + break; + case '#': // possible YAML/shell style comment + if (isEnabled(JsonReadFeature.ALLOW_YAML_COMMENTS)) { + return; + } + break; + } + // Align `_inputPtr` with what `_reportUnexpectedNumberChar` -> + // `_currentLocationMinusOne()` expects (one past the offending char), + // matching `_verifyRootSpace` which advances up front. + ++_inputPtr; + _reportUnexpectedNumberChar(ch, + "expected space, comma, or closing bracket/brace to separate or terminate numeric value"); + } + /* /********************************************************************** /* Internal methods, secondary parsing diff --git a/src/main/java/tools/jackson/core/json/UTF8DataInputJsonParser.java b/src/main/java/tools/jackson/core/json/UTF8DataInputJsonParser.java index 778342b049..b56fa80c94 100644 --- a/src/main/java/tools/jackson/core/json/UTF8DataInputJsonParser.java +++ b/src/main/java/tools/jackson/core/json/UTF8DataInputJsonParser.java @@ -1092,11 +1092,9 @@ protected JsonToken _parseUnsignedNumber(int c) throws IOException return _parseFloat(outBuf, outPtr, c, false, intLen); } _textBuffer.setCurrentLength(outPtr); - // As per [core#105], need separating space between root values; check here + // [core#105]/[core#1557]: verify number is properly terminated/separated _nextByte = c; - if (_streamReadContext.inRoot()) { - _verifyRootSpace(); - } + _verifyNumberSeparator(); // And there we have it! return resetInt(false, intLen); } @@ -1160,11 +1158,9 @@ private final JsonToken _parseSignedNumber(boolean negative) throws IOException return _parseFloat(outBuf, outPtr, c, negative, intLen); } _textBuffer.setCurrentLength(outPtr); - // As per [core#105], need separating space between root values; check here + // [core#105]/[core#1557]: verify number is properly terminated/separated _nextByte = c; - if (_streamReadContext.inRoot()) { - _verifyRootSpace(); - } + _verifyNumberSeparator(); // And there we have it! return resetInt(negative, intLen); } @@ -1209,9 +1205,7 @@ private final JsonToken _finishHexNumber(boolean neg, char[] outBuf, int outPtr, } _textBuffer.setCurrentLength(outPtr); _nextByte = c; - if (_streamReadContext.inRoot()) { - _verifyRootSpace(); - } + _verifyNumberSeparator(); return resetIntHex(neg, hexLen); } @@ -1313,11 +1307,9 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c, } // Ok; unless we hit end-of-input, need to push last char read back - // As per #105, need separating space between root values; check here + // [core#105]/[core#1557]: verify number is properly terminated/separated _nextByte = c; - if (_streamReadContext.inRoot()) { - _verifyRootSpace(); - } + _verifyNumberSeparator(); _textBuffer.setCurrentLength(outPtr); // And there we have it! @@ -1345,6 +1337,53 @@ private final void _verifyRootSpace() throws JacksonException _reportMissingRootWS(ch); } + /** + * Method called to verify that a just-decoded number value is followed by a + * valid separator or terminator. For root-level values this means white space + * (as per [core#105], see {@link #_verifyRootSpace}); for non-root values + * ([core#1557]) the number must be followed by white space, a value separator + * ({@code ','}), an enclosing-structure end ({@code ']'} or {@code '}'}), a + * comment start (when enabled) or end-of-input. Without this, malformed content + * such as {@code [ 123true ]} would only fail lazily when accessing the + * following token. + *

+ * The trailing character is held in {@code _nextByte}; for accepted separators + * it is left there so the next {@code nextToken()} call can consume it normally. + */ + private final void _verifyNumberSeparator() throws JacksonException + { + if (_streamReadContext.inRoot()) { + _verifyRootSpace(); + return; + } + final int ch = _nextByte; + if (ch < 0) { // end-of-input: number itself is complete + return; + } + switch (ch) { + case ' ': + case '\t': + case '\n': + case '\r': + case ',': + case ']': + case '}': + return; + case '/': // possible Java/C++ style comment + if (isEnabled(JsonReadFeature.ALLOW_JAVA_COMMENTS)) { + return; + } + break; + case '#': // possible YAML/shell style comment + if (isEnabled(JsonReadFeature.ALLOW_YAML_COMMENTS)) { + return; + } + break; + } + _reportUnexpectedNumberChar(ch, + "expected space, comma, or closing bracket/brace to separate or terminate numeric value"); + } + /* /********************************************************************** /* Internal methods, secondary parsing diff --git a/src/main/java/tools/jackson/core/json/UTF8StreamJsonParser.java b/src/main/java/tools/jackson/core/json/UTF8StreamJsonParser.java index 0794e2ad9e..b43fb2516f 100644 --- a/src/main/java/tools/jackson/core/json/UTF8StreamJsonParser.java +++ b/src/main/java/tools/jackson/core/json/UTF8StreamJsonParser.java @@ -1856,10 +1856,8 @@ protected JsonToken _parseUnsignedNumber(int c) throws JacksonException } --_inputPtr; // to push back trailing char (comma etc) _textBuffer.setCurrentLength(outPtr); - // As per #105, need separating space between root values; check here - if (_streamReadContext.inRoot()) { - _verifyRootSpace(c); - } + // [core#105]/[core#1557]: verify number is properly terminated/separated + _verifyNumberSeparator(c); // And there we have it! return resetInt(false, intLen); } @@ -1925,10 +1923,8 @@ private final JsonToken _parseSignedNumber(boolean negative) throws JacksonExcep --_inputPtr; // to push back trailing char (comma etc) _textBuffer.setCurrentLength(outPtr); - // As per #105, need separating space between root values; check here - if (_streamReadContext.inRoot()) { - _verifyRootSpace(c); - } + // [core#105]/[core#1557]: verify number is properly terminated/separated + _verifyNumberSeparator(c); // And there we have it! return resetInt(negative, intLen); @@ -1961,10 +1957,8 @@ private final JsonToken _parseNumber2(char[] outBuf, int outPtr, boolean negativ } --_inputPtr; // to push back trailing char (comma etc) _textBuffer.setCurrentLength(outPtr); - // As per #105, need separating space between root values; check here - if (_streamReadContext.inRoot()) { - _verifyRootSpace(_inputBuffer[_inputPtr] & 0xFF); - } + // [core#105]/[core#1557]: verify number is properly terminated/separated + _verifyNumberSeparator(_inputBuffer[_inputPtr] & 0xFF); // And there we have it! return resetInt(negative, intPartLength); @@ -2025,9 +2019,7 @@ private final JsonToken _finishHexNumber(boolean neg, char[] outBuf, int outPtr, if (!eof) { --_inputPtr; // push back the terminating non-hex char - if (_streamReadContext.inRoot()) { - _verifyRootSpace(c); - } + _verifyNumberSeparator(c); } _textBuffer.setCurrentLength(outPtr); return resetIntHex(neg, hexLen); @@ -2157,10 +2149,8 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c, // Ok; unless we hit end-of-input, need to push last char read back if (!eof) { --_inputPtr; - // As per [core#105], need separating space between root values; check here - if (_streamReadContext.inRoot()) { - _verifyRootSpace(c); - } + // [core#105]/[core#1557]: verify number is properly terminated/separated + _verifyNumberSeparator(c); } _textBuffer.setCurrentLength(outPtr); @@ -2203,6 +2193,54 @@ private final void _verifyRootSpace(int ch) throws JacksonException _reportMissingRootWS(ch); } + /** + * Method called to verify that a just-decoded number value is followed by a + * valid separator or terminator character. For root-level values this means + * white space (as per [core#105], see {@link #_verifyRootSpace}); for non-root + * values ([core#1557]) the number must be followed by white space, a value + * separator ({@code ','}), an enclosing-structure end ({@code ']'} or + * {@code '}'}), a comment start (when enabled) or end-of-input. Without this, + * malformed content such as {@code [ 123true ]} would only fail lazily when + * accessing the following token. + *

+ * On entry the caller has pushed the trailing character back, so {@code _inputPtr} + * points at it; for accepted separators this method leaves {@code _inputPtr} + * untouched so the next {@code nextToken()} call can consume them normally. + */ + private final void _verifyNumberSeparator(int ch) throws JacksonException + { + if (_streamReadContext.inRoot()) { + _verifyRootSpace(ch); + return; + } + switch (ch) { + case ' ': + case '\t': + case '\n': + case '\r': + case ',': + case ']': + case '}': + return; + case '/': // possible Java/C++ style comment + if (isEnabled(JsonReadFeature.ALLOW_JAVA_COMMENTS)) { + return; + } + break; + case '#': // possible YAML/shell style comment + if (isEnabled(JsonReadFeature.ALLOW_YAML_COMMENTS)) { + return; + } + break; + } + // Align `_inputPtr` with what `_reportUnexpectedNumberChar` -> + // `_currentLocationMinusOne()` expects (one past the offending char), + // matching `_verifyRootSpace` which advances up front. + ++_inputPtr; + _reportUnexpectedNumberChar(ch, + "expected space, comma, or closing bracket/brace to separate or terminate numeric value"); + } + /* /********************************************************************** /* Internal methods, secondary parsing diff --git a/src/test/java/module-info.java b/src/test/java/module-info.java index 788d61d9d6..54a6eab6e8 100644 --- a/src/test/java/module-info.java +++ b/src/test/java/module-info.java @@ -34,7 +34,6 @@ opens tools.jackson.core.unittest.jsonptr; opens tools.jackson.core.unittest.read; opens tools.jackson.core.unittest.read.loc; - opens tools.jackson.core.unittest.tofix; opens tools.jackson.core.unittest.tofix.async; opens tools.jackson.core.unittest.sym; opens tools.jackson.core.unittest.type; diff --git a/src/test/java/tools/jackson/core/unittest/read/NonStandardNumberParsingTest.java b/src/test/java/tools/jackson/core/unittest/read/NonStandardNumberParsingTest.java index 849c4f7107..28315771b6 100644 --- a/src/test/java/tools/jackson/core/unittest/read/NonStandardNumberParsingTest.java +++ b/src/test/java/tools/jackson/core/unittest/read/NonStandardNumberParsingTest.java @@ -26,6 +26,11 @@ class NonStandardNumberParsingTest .enable(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS) .build(); + private final JsonFactory COMMENTS_F = JsonFactory.builder() + .enable(JsonReadFeature.ALLOW_JAVA_COMMENTS) + .enable(JsonReadFeature.ALLOW_YAML_COMMENTS) + .build(); + protected JsonFactory jsonFactory() { return JSON_F; } @@ -141,6 +146,63 @@ void test2DecimalPointsInArray() throws Exception { } } + // [core#1557]: number values inside containers (non-root) must be properly + // terminated/separated too, not only at root level (cf. [core#105]); without + // this such content would only fail lazily when accessing the following token. + // NOTE: async (non-blocking) parser still handled lazily; see follow-up. + @Test + void nonRootMangledIntegers1557() throws Exception { + for (int mode : ALL_MODES) { + _verifyMangledNonRootNumber(mode, "[ 123true ]"); + _verifyMangledNonRootNumber(mode, "[ 100k ]"); + _verifyMangledNonRootNumber(mode, "[ 100/ ]"); + } + } + + @Test + void nonRootMangledFloats1557() throws Exception { + for (int mode : ALL_MODES) { + _verifyMangledNonRootNumber(mode, "[ 1.5false ]"); + _verifyMangledNonRootNumber(mode, "[ 1.5x ]"); + } + } + + // [core#1557]: a number immediately followed by a comment (no separating + // white space) must still parse when comments are enabled; this exercises the + // '/' and '#' branches of the separator check that the plain cases never reach. + @Test + void nonRootNumberFollowedByComment1557() throws Exception { + for (int mode : ALL_MODES) { + _verifyTwoIntsAcrossComment(mode, "[1/* c */,2]"); // Java block comment + _verifyTwoIntsAcrossComment(mode, "[1// c\n,2]"); // Java line comment + _verifyTwoIntsAcrossComment(mode, "[1#c\n,2]"); // YAML/shell comment + } + } + + private void _verifyTwoIntsAcrossComment(int mode, String doc) throws Exception { + try (JsonParser p = createParser(COMMENTS_F, mode, doc)) { + assertEquals(JsonToken.START_ARRAY, p.nextToken()); + assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken()); + assertEquals(1, p.getIntValue()); + assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken()); + assertEquals(2, p.getIntValue()); + assertEquals(JsonToken.END_ARRAY, p.nextToken()); + } + } + + private void _verifyMangledNonRootNumber(int mode, String doc) throws Exception { + try (JsonParser p = createParser(mode, doc)) { + assertEquals(JsonToken.START_ARRAY, p.nextToken()); + // Should fail eagerly when decoding the number token (and, at the + // latest, when forcing numeric value access); must NOT silently pass. + JsonToken t = p.nextToken(); + p.getDoubleValue(); + fail("Should have failed for '"+doc+"', instead got token "+t); + } catch (StreamReadException e) { + verifyException(e, "expected space"); + } + } + /** * The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail */ diff --git a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandling1557Test.java b/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandling1557Test.java deleted file mode 100644 index 372ed26f4a..0000000000 --- a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandling1557Test.java +++ /dev/null @@ -1,103 +0,0 @@ -package tools.jackson.core.unittest.tofix; - -import org.junit.jupiter.api.Test; - -import tools.jackson.core.JsonParser; -import tools.jackson.core.JsonToken; -import tools.jackson.core.exc.StreamReadException; -import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -//Failing tests for non-root-token problem [core#1557] -class ParserErrorHandling1557Test - extends tools.jackson.core.unittest.JacksonCoreTestBase -{ - // [core#1557] - @JacksonTestFailureExpected - @Test - void nonRootMangledFloats1557Bytes() throws Exception { - _testNonRootMangledFloats1557(MODE_INPUT_STREAM); - _testNonRootMangledFloats1557(MODE_INPUT_STREAM_THROTTLED); - } - - // [core#1557] - @JacksonTestFailureExpected - @Test - void nonRootMangledFloats1557DataInput() throws Exception { - _testNonRootMangledFloats1557(MODE_DATA_INPUT); - } - - // [core#1557] - @Test - @JacksonTestFailureExpected - void nonRootMangledFloats1557Chars() throws Exception { - _testNonRootMangledFloats1557(MODE_READER); - } - - // [core#1557] - @JacksonTestFailureExpected - @Test - void nonRootMangledInts1557Bytes() throws Exception { - _testNonRootMangledInts(MODE_INPUT_STREAM); - _testNonRootMangledInts(MODE_INPUT_STREAM_THROTTLED); - } - - // [core#1557] - @JacksonTestFailureExpected - @Test - void nonRootMangledInts1557DataInput() throws Exception { - _testNonRootMangledInts(MODE_DATA_INPUT); - } - - // [core#1557] - @JacksonTestFailureExpected - @Test - void nonRootMangledInts1557Chars() throws Exception { - _testNonRootMangledInts(MODE_READER); - } - - /* - /********************************************************************** - /* Helper methods - /********************************************************************** - */ - - private void _testNonRootMangledFloats1557(int mode) throws Exception { - _testNonRootMangledFloats1557(mode, "1.5x"); - } - - private void _testNonRootMangledFloats1557(int mode, String value) throws Exception - { - // Also test with floats - try (JsonParser p = createParser(mode, "[ "+value+" ]")) { - assertEquals(JsonToken.START_ARRAY, p.nextToken()); - JsonToken t = p.nextToken(); - Double v = p.getDoubleValue(); - fail("Should have gotten an exception for '"+value+"'; instead got ("+t+") number: "+v); - } catch (StreamReadException e) { - verifyException(e, "expected "); - } - } - - private void _testNonRootMangledInts(int mode) throws Exception { - _testNonRootMangledInts(mode, "100k"); - _testNonRootMangledInts(mode, "100/"); - } - - private void _testNonRootMangledInts(int mode, String value) throws Exception - { - // Also test with floats - try (JsonParser p = createParser(mode, "[ "+value+" ]")) { - assertEquals(JsonToken.START_ARRAY, p.nextToken()); - try { - JsonToken t = p.nextToken(); - int v = p.getIntValue(); - fail("Should have gotten an exception for '" + value + "'; instead got (" + t + ") number: " + v); - } catch (StreamReadException e) { - verifyException(e, "expected "); - } - } - } -} diff --git a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingBytes1557Test.java b/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingBytes1557Test.java deleted file mode 100644 index 4a258d62fe..0000000000 --- a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingBytes1557Test.java +++ /dev/null @@ -1,57 +0,0 @@ -package tools.jackson.core.unittest.tofix; - -import org.junit.jupiter.api.Test; - -import tools.jackson.core.JsonParser; -import tools.jackson.core.JsonToken; -import tools.jackson.core.exc.StreamReadException; -import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected; - -import static org.junit.jupiter.api.Assertions.fail; - -// Failing tests for non-root-token problem -class ParserErrorHandlingBytes1557Test - extends tools.jackson.core.unittest.JacksonCoreTestBase -{ - @JacksonTestFailureExpected - @Test - void mangledIntsBytes() throws Exception { - _testMangledNonRootInts(MODE_INPUT_STREAM); - _testMangledNonRootInts(MODE_INPUT_STREAM_THROTTLED); - } - - @JacksonTestFailureExpected - @Test - void mangledFloatsBytes() throws Exception { - _testMangledNonRootFloats(MODE_INPUT_STREAM); - _testMangledNonRootFloats(MODE_INPUT_STREAM_THROTTLED); - } - - /* - /********************************************************** - /* Helper methods - /********************************************************** - */ - - private void _testMangledNonRootInts(int mode) - { - try (JsonParser p = createParser(mode, "[ 123true ]")) { - assertToken(JsonToken.START_ARRAY, p.nextToken()); - JsonToken t = p.nextToken(); - fail("Should have gotten an exception; instead got token: "+t); - } catch (StreamReadException e) { - verifyException(e, "expected space"); - } - } - - private void _testMangledNonRootFloats(int mode) - { - try (JsonParser p = createParser(mode, "[ 1.5false ]")) { - assertToken(JsonToken.START_ARRAY, p.nextToken()); - JsonToken t = p.nextToken(); - fail("Should have gotten an exception; instead got token: "+t); - } catch (StreamReadException e) { - verifyException(e, "expected space"); - } - } -} diff --git a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingChars1557Test.java b/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingChars1557Test.java deleted file mode 100644 index 05ed0c49b1..0000000000 --- a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingChars1557Test.java +++ /dev/null @@ -1,55 +0,0 @@ -package tools.jackson.core.unittest.tofix; - -import org.junit.jupiter.api.Test; - -import tools.jackson.core.JsonParser; -import tools.jackson.core.JsonToken; -import tools.jackson.core.exc.StreamReadException; -import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected; - -import static org.junit.jupiter.api.Assertions.fail; - -// Failing tests for non-root-token problem [core#1557] -class ParserErrorHandlingChars1557Test - extends tools.jackson.core.unittest.JacksonCoreTestBase -{ - @JacksonTestFailureExpected - @Test - void mangledIntsChars() throws Exception { - _testMangledNonRootInts(MODE_READER); - } - - @JacksonTestFailureExpected - @Test - void mangledFloatsChars() throws Exception { - _testMangledNonRootFloats(MODE_READER); - } - - /* - /********************************************************** - /* Helper methods - /********************************************************** - */ - - private void _testMangledNonRootInts(int mode) - { - try (JsonParser p = createParser(mode, "[ 123true ]")) { - assertToken(JsonToken.START_ARRAY, p.nextToken()); - JsonToken t = p.nextToken(); - fail("Should have gotten an exception; instead got token: "+t); - } catch (StreamReadException e) { - verifyException(e, "expected space"); - } - } - - private void _testMangledNonRootFloats(int mode) - { - try (JsonParser p = createParser(mode, "[ 1.5false ]")) { - assertToken(JsonToken.START_ARRAY, p.nextToken()); - JsonToken t = p.nextToken(); - fail("Should have gotten an exception; instead got token: "+t); - } catch (StreamReadException e) { - verifyException(e, "expected space"); - } - } -} diff --git a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingDataInput1557Test.java b/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingDataInput1557Test.java deleted file mode 100644 index 87fd14e8f3..0000000000 --- a/src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingDataInput1557Test.java +++ /dev/null @@ -1,57 +0,0 @@ -package tools.jackson.core.unittest.tofix; - -import org.junit.jupiter.api.Test; - -import tools.jackson.core.JsonParser; -import tools.jackson.core.JsonToken; -import tools.jackson.core.exc.StreamReadException; -import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected; - -import static org.junit.jupiter.api.Assertions.fail; - -// Failing tests for non-root-token problem [core#1557] -class ParserErrorHandlingDataInput1557Test - extends tools.jackson.core.unittest.JacksonCoreTestBase -{ - @JacksonTestFailureExpected - @Test - void mangledIntsDataInput() throws Exception { - // 02-Jun-2017, tatu: Fails to fail; should check whether this is expected - // (since DataInput can't do look-ahead) - _testMangledNonRootInts(MODE_DATA_INPUT); - } - - @JacksonTestFailureExpected - @Test - void mangledFloatsDataInput() throws Exception { - _testMangledNonRootFloats(MODE_DATA_INPUT); - } - - /* - /********************************************************** - /* Helper methods - /********************************************************** - */ - - private void _testMangledNonRootInts(int mode) - { - try (JsonParser p = createParser(mode, "[ 123true ]")) { - assertToken(JsonToken.START_ARRAY, p.nextToken()); - JsonToken t = p.nextToken(); - fail("Should have gotten an exception; instead got token: "+t); - } catch (StreamReadException e) { - verifyException(e, "expected space"); - } - } - - private void _testMangledNonRootFloats(int mode) - { - try (JsonParser p = createParser(mode, "[ 1.5false ]")) { - assertToken(JsonToken.START_ARRAY, p.nextToken()); - JsonToken t = p.nextToken(); - fail("Should have gotten an exception; instead got token: "+t); - } catch (StreamReadException e) { - verifyException(e, "expected space"); - } - } -}