Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/json/JSONPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Object queryFrom(Object document) throws JSONPointerException {
Object current = document;
for (String token : this.refTokens) {
if (current instanceof JSONObject) {
current = ((JSONObject) current).opt(unescape(token));
current = ((JSONObject) current).opt(token);
} else if (current instanceof JSONArray) {
current = readByIndexToken(current, token);
} else {
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/json/junit/JSONPointerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ public void tildeEscaping() {
assertEquals(8, query("/m~0n"));
}

@Test
public void escapeSequencesInObjectKeys() {
JSONObject object = new JSONObject().put("~1", "tilde one").put("/", "slash")
.put("~0", "tilde zero").put("~", "tilde");
assertEquals("tilde one", object.query("/~01"));
assertEquals("tilde zero", object.query("/~00"));
assertEquals("tilde one", object.query("#/~01"));
assertEquals("tilde zero", object.query("#/~00"));
}

@Test
public void builderPreservesLiteralTokens() {
JSONObject object = new JSONObject().put("~1", "tilde one").put("/", "slash")
.put("~0", "tilde zero").put("~", "tilde");
assertEquals("tilde one", JSONPointer.builder().append("~1").build().queryFrom(object));
assertEquals("tilde zero", JSONPointer.builder().append("~0").build().queryFrom(object));
}

@Test
public void tokenListPreservesLiteralTokens() {
JSONObject object = new JSONObject().put("~1", "tilde one").put("/", "slash")
.put("~0", "tilde zero").put("~", "tilde");
assertEquals("tilde one", new JSONPointer(java.util.Arrays.asList("~1")).queryFrom(object));
assertEquals("tilde zero", new JSONPointer(java.util.Arrays.asList("~0")).queryFrom(object));
}

/**
* We pass backslashes as-is
*
Expand Down
Loading