Skip to content

Commit

Permalink
Backport FasterXML#1168 in 2.16(.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 15, 2023
1 parent 571d4ae commit 4eb4539
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ a pure JSON library.
(reported by @TimSchweers)
#1161: NPE in "FastDoubleParser", method "JavaBigDecimalParser.parseBigDecimal()"
(contributed by @pjfanning)
#1168: `JsonPointer.append(JsonPointer.tail())` includes the original pointer
(contributed by Robert E)

2.16.0 (15-Nov-2023)

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/fasterxml/jackson/core/JsonPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,12 @@ public JsonPointer append(JsonPointer tail) {
// 21-Mar-2017, tatu: Not superbly efficient; could probably improve by not concatenating,
// re-decoding -- by stitching together segments -- but for now should be fine.

String currentJsonPointer = _asString;
String currentJsonPointer = toString();
if (currentJsonPointer.endsWith("/")) {
//removes final slash
currentJsonPointer = currentJsonPointer.substring(0, currentJsonPointer.length()-1);
}
return compile(currentJsonPointer + tail._asString);
return compile(currentJsonPointer + tail.toString());
}

/**
Expand Down Expand Up @@ -408,7 +408,7 @@ public JsonPointer appendProperty(String property) {
if (property.charAt(0) != SEPARATOR) {
property = SEPARATOR + property;
}
String currentJsonPointer = _asString;
String currentJsonPointer = toString();
if (currentJsonPointer.endsWith("/")) {
//removes final slash
currentJsonPointer = currentJsonPointer.substring(0, currentJsonPointer.length()-1);
Expand All @@ -432,7 +432,7 @@ public JsonPointer appendIndex(int index) {
if (index < 0) {
throw new IllegalArgumentException("Negative index cannot be appended");
}
String currentJsonPointer = _asString;
String currentJsonPointer = toString();
if (currentJsonPointer.endsWith("/")) {
//removes final slash
currentJsonPointer = currentJsonPointer.substring(0, currentJsonPointer.length()-1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fasterxml.jackson.core.jsonptr;

import com.fasterxml.jackson.core.BaseTest;
import com.fasterxml.jackson.core.JsonPointer;

public class JsonPointer1168Test extends BaseTest
{
// [core#1168]
public void testAppendWithTail()
{
JsonPointer original = JsonPointer.compile("/a1/b/c");
JsonPointer tailPointer = original.tail();
assertEquals("/b/c", tailPointer.toString());

JsonPointer other = JsonPointer.compile("/a2");
assertEquals("/a2", other.toString());

assertEquals("/a2/b/c", other.append(tailPointer).toString());

// And the other way around too
assertEquals("/b/c/a2", tailPointer.append(other).toString());

// And with `appendProperty()`
assertEquals("/b/c/xyz", tailPointer.appendProperty("xyz").toString());
}
}

0 comments on commit 4eb4539

Please sign in to comment.