mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-09 12:04:28 +08:00
escape handling improvements & URL fragment notation handling
This commit is contained in:
@@ -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) {
|
||||||
|
Reference in New Issue
Block a user