mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
Closes 563: As never defined in RFC 6901 Section 3, do not handle backslashes (\) and quotes(") as anything special
This commit is contained in:
parent
7844eb79cd
commit
d6ccc64c79
@ -187,10 +187,11 @@ public class JSONPointer {
|
|||||||
this.refTokens = new ArrayList<String>(refTokens);
|
this.refTokens = new ArrayList<String>(refTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://tools.ietf.org/html/rfc6901#section-3
|
||||||
|
*/
|
||||||
private static String unescape(String token) {
|
private static String unescape(String token) {
|
||||||
return token.replace("~1", "/").replace("~0", "~")
|
return token.replace("~1", "/").replace("~0", "~");
|
||||||
.replace("\\\"", "\"")
|
|
||||||
.replace("\\\\", "\\");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -263,16 +264,15 @@ public class JSONPointer {
|
|||||||
/**
|
/**
|
||||||
* Escapes path segment values to an unambiguous form.
|
* Escapes path segment values to an unambiguous form.
|
||||||
* The escape char to be inserted is '~'. The chars to be escaped
|
* The escape char to be inserted is '~'. The chars to be escaped
|
||||||
* are ~, which maps to ~0, and /, which maps to ~1. Backslashes
|
* are ~, which maps to ~0, and /, which maps to ~1.
|
||||||
* and double quote chars are also escaped.
|
|
||||||
* @param token the JSONPointer segment value to be escaped
|
* @param token the JSONPointer segment value to be escaped
|
||||||
* @return the escaped value for the token
|
* @return the escaped value for the token
|
||||||
|
*
|
||||||
|
* @see https://tools.ietf.org/html/rfc6901#section-3
|
||||||
*/
|
*/
|
||||||
private static String escape(String token) {
|
private static String escape(String token) {
|
||||||
return token.replace("~", "~0")
|
return token.replace("~", "~0")
|
||||||
.replace("/", "~1")
|
.replace("/", "~1");
|
||||||
.replace("\\", "\\\\")
|
|
||||||
.replace("\"", "\\\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,14 +117,24 @@ public class JSONPointerTest {
|
|||||||
assertSame(document.get("m~n"), query("/m~0n"));
|
assertSame(document.get("m~n"), query("/m~0n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We pass backslashes as-is
|
||||||
|
*
|
||||||
|
* @see https://tools.ietf.org/html/rfc6901#section-3
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void backslashEscaping() {
|
public void backslashHandling() {
|
||||||
assertSame(document.get("i\\j"), query("/i\\\\j"));
|
assertSame(document.get("i\\j"), query("/i\\j"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We pass quotations as-is
|
||||||
|
*
|
||||||
|
* @see https://tools.ietf.org/html/rfc6901#section-3
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void quotationEscaping() {
|
public void quotationHandling() {
|
||||||
assertSame(document.get("k\"l"), query("/k\\\\\\\"l"));
|
assertSame(document.get("k\"l"), query("/k\"l"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -189,7 +199,7 @@ public class JSONPointerTest {
|
|||||||
.append("\"")
|
.append("\"")
|
||||||
.append(0)
|
.append(0)
|
||||||
.build();
|
.build();
|
||||||
assertEquals("/obj/other~0key/another~1key/\\\"/0", pointer.toString());
|
assertEquals("/obj/other~0key/another~1key/\"/0", pointer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user