Skip to content

Commit

Permalink
Fix #220
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 30, 2015
1 parent 603179e commit 186a639
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 30 deletions.
4 changes: 4 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ JSON library.
=== Releases ===
------------------------------------------------------------------------

2.6.3 (not yet released)

#220: Problem with `JsonParser.nextFieldName(SerializableString)` for byte-backed parser

2.6.2 (14-Sep-2015)

#213: Parser is sometimes wrong when using CANONICALIZE_FIELD_NAMES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ public boolean nextFieldName(SerializableString str) throws IOException
while (true) {
if (ptr == end) { // yes, match!
_parsingContext.setCurrentName(str.getValue());
_isNextTokenNameYes(_skipColonFast(ptr+1));
i = _skipColonFast(ptr+1);
_isNextTokenNameYes(i);
return true;
}
if (nameBytes[offset] != _inputBuffer[ptr]) {
Expand Down Expand Up @@ -1099,6 +1100,8 @@ private final int _skipColonFast(int ptr) throws IOException
}
}
}
_inputPtr = ptr-1;
return _skipColon2(true);
}
_inputPtr = ptr-1;
return _skipColon2(false);
Expand Down Expand Up @@ -2980,7 +2983,7 @@ private final int _skipColon() throws IOException
}
return _skipColon2(false);
}

private final int _skipColon2(boolean gotColon) throws IOException
{
while (_inputPtr < _inputEnd || loadMore()) {
Expand Down
78 changes: 51 additions & 27 deletions src/test/java/com/fasterxml/jackson/core/json/TestNextXxx.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class TestNextXxx

private final JsonFactory JSON_F = new JsonFactory();

// [JACKSON-653]
public void testIsNextTokenName() throws Exception
{
_testIsNextTokenName1(false);
Expand All @@ -32,14 +31,14 @@ public void testIsNextTokenName() throws Exception
_testIsNextTokenName3(true);
}

// [Issue#34]
// [jackson-core#34]
public void testIssue34() throws Exception
{
_testIssue34(false);
_testIssue34(true);
}

// [Issue#38] with nextFieldName
// [jackson-core#38] with nextFieldName
public void testIssue38() throws Exception
{
_testIssue38(false);
Expand All @@ -52,6 +51,13 @@ public void testNextNameWithLongContent() throws Exception
_testNextNameWithLong(true);
}

// for [core#220]: problem with `nextFieldName(str)`, indented content
public void testNextNameWithIndentation() throws Exception
{
_testNextFieldNameIndent(false);
_testNextFieldNameIndent(true);
}

public void testNextTextValue() throws Exception
{
_textNextText(false);
Expand Down Expand Up @@ -194,40 +200,58 @@ private void _testIsNextTokenName2(boolean useStream) throws Exception
private void _testIsNextTokenName3(boolean useStream) throws Exception
{
final String DOC = "{\"name\":123,\"name2\":14,\"x\":\"name\"}";
JsonParser jp = useStream ?
JsonParser p = useStream ?
JSON_F.createParser(new ByteArrayInputStream(DOC.getBytes("UTF-8")))
: JSON_F.createParser(new StringReader(DOC));
assertNull(jp.nextFieldName());
assertToken(JsonToken.START_OBJECT, jp.getCurrentToken());
assertEquals("name", jp.nextFieldName());
assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
assertEquals("name", jp.getCurrentName());
assertEquals("name", jp.getText());
assertNull(jp.nextFieldName());
assertToken(JsonToken.VALUE_NUMBER_INT, jp.getCurrentToken());
assertEquals(123, jp.getIntValue());
assertNull(p.nextFieldName());
assertToken(JsonToken.START_OBJECT, p.getCurrentToken());
assertEquals("name", p.nextFieldName());
assertToken(JsonToken.FIELD_NAME, p.getCurrentToken());
assertEquals("name", p.getCurrentName());
assertEquals("name", p.getText());
assertNull(p.nextFieldName());
assertToken(JsonToken.VALUE_NUMBER_INT, p.getCurrentToken());
assertEquals(123, p.getIntValue());

assertEquals("name2", jp.nextFieldName());
assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
assertEquals("name2", jp.getCurrentName());
assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
assertEquals("name2", p.nextFieldName());
assertToken(JsonToken.FIELD_NAME, p.getCurrentToken());
assertEquals("name2", p.getCurrentName());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());

assertEquals("x", jp.nextFieldName());
assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
assertEquals("x", jp.getCurrentName());
assertEquals("x", p.nextFieldName());
assertToken(JsonToken.FIELD_NAME, p.getCurrentToken());
assertEquals("x", p.getCurrentName());

assertNull(jp.nextFieldName());
assertToken(JsonToken.VALUE_STRING, jp.getCurrentToken());
assertNull(p.nextFieldName());
assertToken(JsonToken.VALUE_STRING, p.getCurrentToken());

assertNull(jp.nextFieldName());
assertToken(JsonToken.END_OBJECT, jp.getCurrentToken());
assertNull(p.nextFieldName());
assertToken(JsonToken.END_OBJECT, p.getCurrentToken());

assertNull(jp.nextFieldName());
assertNull(jp.getCurrentToken());
assertNull(p.nextFieldName());
assertNull(p.getCurrentToken());

jp.close();
p.close();
}

private void _testNextFieldNameIndent(boolean useStream) throws Exception
{
final String DOC = "{\n \"name\" : \n [\n ]\n }";
JsonParser p = useStream ?
JSON_F.createParser(new ByteArrayInputStream(DOC.getBytes("UTF-8")))
: JSON_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 _textNextText(boolean useStream) throws Exception
{
final String DOC = aposToQuotes("{'a':'123','b':5,'c':[false,'foo']}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.fasterxml.jackson.core.sym;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashSet;

Expand Down

0 comments on commit 186a639

Please sign in to comment.