Skip to content

Commit 5bee7e3

Browse files
committed
escape handling improvements & URL fragment notation handling
1 parent 612e419 commit 5bee7e3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

JSONPointer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static java.lang.String.format;
44
import static java.util.Collections.emptyList;
55

6+
import java.io.UnsupportedEncodingException;
7+
import java.net.URLDecoder;
68
import java.util.ArrayList;
79
import java.util.List;
810

@@ -20,6 +22,11 @@ public JSONPointer(String pointer) {
2022
}
2123
if (pointer.startsWith("#/")) {
2224
pointer = pointer.substring(2);
25+
try {
26+
pointer = URLDecoder.decode(pointer, "utf-8");
27+
} catch (UnsupportedEncodingException e) {
28+
throw new RuntimeException(e);
29+
}
2330
} else if (pointer.startsWith("/")) {
2431
pointer = pointer.substring(1);
2532
} else {
@@ -32,7 +39,9 @@ public JSONPointer(String pointer) {
3239
}
3340

3441
private String unescape(String token) {
35-
return token.replace("~1", "/").replace("~0", "~");
42+
return token.replace("~1", "/").replace("~0", "~")
43+
.replace("\\\"", "\"")
44+
.replace("\\\\", "\\");
3645
}
3746

3847
public Object queryFrom(JSONObject document) {

0 commit comments

Comments
 (0)