1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

escape handling improvements & URL fragment notation handling

This commit is contained in:
Bence Erős 2016-04-26 23:00:16 +02:00
parent 612e41950c
commit 5bee7e3b45

View file

@ -3,6 +3,8 @@ package org.json;
import static java.lang.String.format; import static java.lang.String.format;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -20,6 +22,11 @@ public class JSONPointer {
} }
if (pointer.startsWith("#/")) { if (pointer.startsWith("#/")) {
pointer = pointer.substring(2); pointer = pointer.substring(2);
try {
pointer = URLDecoder.decode(pointer, "utf-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else if (pointer.startsWith("/")) { } else if (pointer.startsWith("/")) {
pointer = pointer.substring(1); pointer = pointer.substring(1);
} else { } else {
@ -32,7 +39,9 @@ public class JSONPointer {
} }
private String unescape(String token) { private String unescape(String token) {
return token.replace("~1", "/").replace("~0", "~"); return token.replace("~1", "/").replace("~0", "~")
.replace("\\\"", "\"")
.replace("\\\\", "\\");
} }
public Object queryFrom(JSONObject document) { public Object queryFrom(JSONObject document) {