Skip to content

Commit 186a639

Browse files
committed
Fix #220
1 parent 603179e commit 186a639

File tree

4 files changed

+60
-30
lines changed

4 files changed

+60
-30
lines changed

release-notes/VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.6.3 (not yet released)
18+
19+
#220: Problem with `JsonParser.nextFieldName(SerializableString)` for byte-backed parser
20+
1721
2.6.2 (14-Sep-2015)
1822

1923
#213: Parser is sometimes wrong when using CANONICALIZE_FIELD_NAMES

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,8 @@ public boolean nextFieldName(SerializableString str) throws IOException
934934
while (true) {
935935
if (ptr == end) { // yes, match!
936936
_parsingContext.setCurrentName(str.getValue());
937-
_isNextTokenNameYes(_skipColonFast(ptr+1));
937+
i = _skipColonFast(ptr+1);
938+
_isNextTokenNameYes(i);
938939
return true;
939940
}
940941
if (nameBytes[offset] != _inputBuffer[ptr]) {
@@ -1099,6 +1100,8 @@ private final int _skipColonFast(int ptr) throws IOException
10991100
}
11001101
}
11011102
}
1103+
_inputPtr = ptr-1;
1104+
return _skipColon2(true);
11021105
}
11031106
_inputPtr = ptr-1;
11041107
return _skipColon2(false);
@@ -2980,7 +2983,7 @@ private final int _skipColon() throws IOException
29802983
}
29812984
return _skipColon2(false);
29822985
}
2983-
2986+
29842987
private final int _skipColon2(boolean gotColon) throws IOException
29852988
{
29862989
while (_inputPtr < _inputEnd || loadMore()) {

src/test/java/com/fasterxml/jackson/core/json/TestNextXxx.java

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class TestNextXxx
2121

2222
private final JsonFactory JSON_F = new JsonFactory();
2323

24-
// [JACKSON-653]
2524
public void testIsNextTokenName() throws Exception
2625
{
2726
_testIsNextTokenName1(false);
@@ -32,14 +31,14 @@ public void testIsNextTokenName() throws Exception
3231
_testIsNextTokenName3(true);
3332
}
3433

35-
// [Issue#34]
34+
// [jackson-core#34]
3635
public void testIssue34() throws Exception
3736
{
3837
_testIssue34(false);
3938
_testIssue34(true);
4039
}
4140

42-
// [Issue#38] with nextFieldName
41+
// [jackson-core#38] with nextFieldName
4342
public void testIssue38() throws Exception
4443
{
4544
_testIssue38(false);
@@ -52,6 +51,13 @@ public void testNextNameWithLongContent() throws Exception
5251
_testNextNameWithLong(true);
5352
}
5453

54+
// for [core#220]: problem with `nextFieldName(str)`, indented content
55+
public void testNextNameWithIndentation() throws Exception
56+
{
57+
_testNextFieldNameIndent(false);
58+
_testNextFieldNameIndent(true);
59+
}
60+
5561
public void testNextTextValue() throws Exception
5662
{
5763
_textNextText(false);
@@ -194,40 +200,58 @@ private void _testIsNextTokenName2(boolean useStream) throws Exception
194200
private void _testIsNextTokenName3(boolean useStream) throws Exception
195201
{
196202
final String DOC = "{\"name\":123,\"name2\":14,\"x\":\"name\"}";
197-
JsonParser jp = useStream ?
203+
JsonParser p = useStream ?
198204
JSON_F.createParser(new ByteArrayInputStream(DOC.getBytes("UTF-8")))
199205
: JSON_F.createParser(new StringReader(DOC));
200-
assertNull(jp.nextFieldName());
201-
assertToken(JsonToken.START_OBJECT, jp.getCurrentToken());
202-
assertEquals("name", jp.nextFieldName());
203-
assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
204-
assertEquals("name", jp.getCurrentName());
205-
assertEquals("name", jp.getText());
206-
assertNull(jp.nextFieldName());
207-
assertToken(JsonToken.VALUE_NUMBER_INT, jp.getCurrentToken());
208-
assertEquals(123, jp.getIntValue());
206+
assertNull(p.nextFieldName());
207+
assertToken(JsonToken.START_OBJECT, p.getCurrentToken());
208+
assertEquals("name", p.nextFieldName());
209+
assertToken(JsonToken.FIELD_NAME, p.getCurrentToken());
210+
assertEquals("name", p.getCurrentName());
211+
assertEquals("name", p.getText());
212+
assertNull(p.nextFieldName());
213+
assertToken(JsonToken.VALUE_NUMBER_INT, p.getCurrentToken());
214+
assertEquals(123, p.getIntValue());
209215

210-
assertEquals("name2", jp.nextFieldName());
211-
assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
212-
assertEquals("name2", jp.getCurrentName());
213-
assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
216+
assertEquals("name2", p.nextFieldName());
217+
assertToken(JsonToken.FIELD_NAME, p.getCurrentToken());
218+
assertEquals("name2", p.getCurrentName());
219+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
214220

215-
assertEquals("x", jp.nextFieldName());
216-
assertToken(JsonToken.FIELD_NAME, jp.getCurrentToken());
217-
assertEquals("x", jp.getCurrentName());
221+
assertEquals("x", p.nextFieldName());
222+
assertToken(JsonToken.FIELD_NAME, p.getCurrentToken());
223+
assertEquals("x", p.getCurrentName());
218224

219-
assertNull(jp.nextFieldName());
220-
assertToken(JsonToken.VALUE_STRING, jp.getCurrentToken());
225+
assertNull(p.nextFieldName());
226+
assertToken(JsonToken.VALUE_STRING, p.getCurrentToken());
221227

222-
assertNull(jp.nextFieldName());
223-
assertToken(JsonToken.END_OBJECT, jp.getCurrentToken());
228+
assertNull(p.nextFieldName());
229+
assertToken(JsonToken.END_OBJECT, p.getCurrentToken());
224230

225-
assertNull(jp.nextFieldName());
226-
assertNull(jp.getCurrentToken());
231+
assertNull(p.nextFieldName());
232+
assertNull(p.getCurrentToken());
227233

228-
jp.close();
234+
p.close();
229235
}
230236

237+
private void _testNextFieldNameIndent(boolean useStream) throws Exception
238+
{
239+
final String DOC = "{\n \"name\" : \n [\n ]\n }";
240+
JsonParser p = useStream ?
241+
JSON_F.createParser(new ByteArrayInputStream(DOC.getBytes("UTF-8")))
242+
: JSON_F.createParser(new StringReader(DOC));
243+
assertToken(JsonToken.START_OBJECT, p.nextToken());
244+
assertTrue(p.nextFieldName(new SerializedString("name")));
245+
246+
assertToken(JsonToken.START_ARRAY, p.nextToken());
247+
assertToken(JsonToken.END_ARRAY, p.nextToken());
248+
assertToken(JsonToken.END_OBJECT, p.nextToken());
249+
250+
assertNull(p.nextToken());
251+
252+
p.close();
253+
}
254+
231255
private void _textNextText(boolean useStream) throws Exception
232256
{
233257
final String DOC = aposToQuotes("{'a':'123','b':5,'c':[false,'foo']}");

src/test/java/com/fasterxml/jackson/core/sym/SymbolsViaParserTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.fasterxml.jackson.core.sym;
22

3-
import java.io.ByteArrayInputStream;
43
import java.io.IOException;
54
import java.util.HashSet;
65

0 commit comments

Comments
 (0)