From 98df182bde0b86157ad1275e70a5d0ccc6dd5885 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 1 Oct 2015 08:08:41 -0700 Subject: [PATCH] Backport #220 fix for 2.5(.5) --- release-notes/VERSION | 4 +++ .../core/json/UTF8StreamJsonParser.java | 2 ++ .../jackson/core/json/TestNextXxx.java | 35 ++++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/release-notes/VERSION b/release-notes/VERSION index cec28e2d81..1d41330aa6 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -14,6 +14,10 @@ JSON library. === Releases === ------------------------------------------------------------------------ +2.5.5 (not yet released) + +#220: Problem with `JsonParser.nextFieldName(SerializableString)` for byte-backed parser + 2.5.4 (09-Jun-2015) No changes. 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 94637b4e9b..8df7c3585c 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java @@ -1065,6 +1065,8 @@ private final int _skipColonFast(int ptr) throws IOException } } } + _inputPtr = ptr-1; + return _skipColon2(true); } _inputPtr = ptr-1; return _skipColon2(false); diff --git a/src/test/java/com/fasterxml/jackson/core/json/TestNextXxx.java b/src/test/java/com/fasterxml/jackson/core/json/TestNextXxx.java index 478b9537c4..8a95c422c0 100644 --- a/src/test/java/com/fasterxml/jackson/core/json/TestNextXxx.java +++ b/src/test/java/com/fasterxml/jackson/core/json/TestNextXxx.java @@ -18,8 +18,7 @@ public class TestNextXxx /* Wrappers to test InputStream vs Reader /******************************************************** */ - - // [JACKSON-653] + public void testIsNextTokenName() throws Exception { _testIsNextTokenName1(false); @@ -30,14 +29,21 @@ public void testIsNextTokenName() throws Exception _testIsNextTokenName3(true); } - // [Issue#34] + // for [core#220]: problem with `nextFieldName(str)`, indented content + public void testNextNameWithIndentation() throws Exception + { + _testNextFieldNameIndent(false); + _testNextFieldNameIndent(true); + } + + // [core#34] public void testIssue34() throws Exception { _testIssue34(false); _testIssue34(true); } - // [Issue#38] with nextFieldName + // [core#38] with nextFieldName public void testIssue38() throws Exception { _testIssue38(false); @@ -51,7 +57,7 @@ public void testNextNameWithLongContent() throws Exception _testLong(jf, false); _testLong(jf, true); } - + /* /******************************************************** /* Actual test code @@ -206,6 +212,25 @@ private void _testIsNextTokenName3(boolean useStream) throws Exception jp.close(); } + private void _testNextFieldNameIndent(boolean useStream) throws Exception + { + final String DOC = "{\n \"name\" : \n [\n ]\n }"; + JsonFactory f = new JsonFactory(); + JsonParser p = useStream ? + f.createParser(new ByteArrayInputStream(DOC.getBytes("UTF-8"))) + : f.createParser(new StringReader(DOC)); + assertToken(JsonToken.START_OBJECT, p.nextToken()); + assertTrue(p.nextFieldName(new SerializedString("name"))); + + assertToken(JsonToken.START_ARRAY, p.nextToken()); + assertToken(JsonToken.END_ARRAY, p.nextToken()); + assertToken(JsonToken.END_OBJECT, p.nextToken()); + + assertNull(p.nextToken()); + + p.close(); + } + private void _testIssue34(boolean useStream) throws Exception { final int TESTROUNDS = 223;