Skip to content

Commit b4e6b56

Browse files
committed
Merge branch '2.13' into 2.14
2 parents 8f64b15 + 2b65ea1 commit b4e6b56

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/main/java/com/fasterxml/jackson/core/JsonPointer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ public static JsonPointer forPath(JsonStreamContext context,
174174
if (context == null) {
175175
return EMPTY;
176176
}
177+
// Otherwise if context was just created but is not advanced -- like,
178+
// opening START_ARRAY/START_OBJECT returned -- drop the empty context.
177179
if (!context.hasPathSegment()) {
178-
// one special case; do not prune root if we need it
180+
// Except one special case: do not prune root if we need it
179181
if (!(includeRoot && context.inRoot() && context.hasCurrentIndex())) {
180182
context = context.getParent();
181183
}

src/test/java/com/fasterxml/jackson/core/read/ParserSymbolHandlingTest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,68 @@ private void _testSymbolsWithNull(JsonFactory f, boolean useBytes) throws Except
5252
assertToken(JsonToken.END_OBJECT, parser.nextToken());
5353
parser.close();
5454
}
55+
56+
// // Additional testing inspired by [dataformats-binary#312]; did not
57+
// // affect JSON backend but wanted to ensure
58+
59+
public void testSymbolsWithNullOnlyNameBytes() throws Exception {
60+
JsonFactory f = new JsonFactory();
61+
_testSymbolsWithNullOnlyNameBytes(f, true);
62+
// and repeat with same factory, just for fun, and to ensure symbol table is fine
63+
_testSymbolsWithNullOnlyNameBytes(f, true);
64+
}
65+
66+
public void testSymbolsWithNullOnlyNameChars() throws Exception {
67+
JsonFactory f = new JsonFactory();
68+
_testSymbolsWithNullOnlyNameBytes(f, false);
69+
_testSymbolsWithNullOnlyNameBytes(f, false);
70+
}
71+
72+
private void _testSymbolsWithNullOnlyNameBytes(JsonFactory f, boolean useBytes) throws Exception
73+
{
74+
final String FIELD1 = "\u0000";
75+
final String FIELD2 = FIELD1 + FIELD1;
76+
final String FIELD3 = FIELD2 + FIELD1;
77+
final String FIELD4 = FIELD3 + FIELD1;
78+
final String QUOTED_NULL = "\\u0000";
79+
80+
final String INPUT = a2q(String.format("{'%s':1, '%s':2, '%s':3, '%s':4}",
81+
QUOTED_NULL, QUOTED_NULL + QUOTED_NULL,
82+
QUOTED_NULL + QUOTED_NULL + QUOTED_NULL,
83+
QUOTED_NULL + QUOTED_NULL + QUOTED_NULL + QUOTED_NULL
84+
));
85+
JsonParser p = useBytes ? f.createParser(INPUT.getBytes("UTF-8"))
86+
: f.createParser(INPUT);
87+
88+
assertToken(JsonToken.START_OBJECT, p.nextToken());
89+
90+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
91+
_assertNullStrings(FIELD1, p.currentName());
92+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
93+
assertEquals(1, p.getIntValue());
94+
95+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
96+
_assertNullStrings(FIELD2, p.currentName());
97+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
98+
assertEquals(2, p.getIntValue());
99+
100+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
101+
_assertNullStrings(FIELD3, p.currentName());
102+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
103+
assertEquals(3, p.getIntValue());
104+
105+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
106+
_assertNullStrings(FIELD4, p.currentName());
107+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
108+
assertEquals(4, p.getIntValue());
109+
110+
assertToken(JsonToken.END_OBJECT, p.nextToken());
111+
}
112+
113+
private void _assertNullStrings(String exp, String actual) {
114+
if (exp.length() != actual.length()) {
115+
fail("Expected "+exp.length()+" nulls, got "+actual.length());
116+
}
117+
assertEquals(exp, actual);
118+
}
55119
}

src/test/java/com/fasterxml/jackson/failing/JsonPointerOOME736Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class JsonPointerOOME736Test extends BaseTest
88
// such as https://github.com/nst/JSONTestSuite/blob/master/test_parsing/n_structure_100000_opening_arrays.json
99
public void testDeepJsonPointer() throws Exception {
1010
int MAX_DEPTH = 100000;
11+
// Create nesting of 100k arrays
1112
String INPUT = new String(new char[MAX_DEPTH]).replace("\0", "[");
1213
JsonParser parser = createParser(MODE_READER, INPUT);
1314
try {

0 commit comments

Comments
 (0)