mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
Merge pull request #640 from katldewitt/561-backslashes
Address #561: Add unit tests for multiple backslashes
This commit is contained in:
commit
d6227c83d7
@ -41,10 +41,11 @@ public class JSONPointerTest {
|
|||||||
|
|
||||||
private static final JSONObject document;
|
private static final JSONObject document;
|
||||||
private static final String EXPECTED_COMPLETE_DOCUMENT = "{\"\":0,\" \":7,\"g|h\":4,\"c%d\":2,\"k\\\"l\":6,\"a/b\":1,\"i\\\\j\":5," +
|
private static final String EXPECTED_COMPLETE_DOCUMENT = "{\"\":0,\" \":7,\"g|h\":4,\"c%d\":2,\"k\\\"l\":6,\"a/b\":1,\"i\\\\j\":5," +
|
||||||
"\"obj\":{\"\":{\"\":\"empty key of an object with an empty key\",\"subKey\":\"Some other value\"}," +
|
"\"obj\":{\"\":{\"\":\"empty key of an object with an empty key\",\"subKey\":\"Some other value\"}," +
|
||||||
"\"other~key\":{\"another/key\":[\"val\"]},\"key\":\"value\"},\"foo\":[\"bar\",\"baz\"],\"e^f\":3," +
|
"\"other~key\":{\"another/key\":[\"val\"]},\"key\":\"value\"},\"foo\":[\"bar\",\"baz\"],\"e^f\":3," +
|
||||||
"\"m~n\":8}";
|
"\"m~n\":8}";
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
InputStream resourceAsStream = JSONPointerTest.class.getClassLoader().getResourceAsStream("jsonpointer-testdoc.json");
|
InputStream resourceAsStream = JSONPointerTest.class.getClassLoader().getResourceAsStream("jsonpointer-testdoc.json");
|
||||||
@ -124,7 +125,7 @@ public class JSONPointerTest {
|
|||||||
public void backslashHandling() {
|
public void backslashHandling() {
|
||||||
assertEquals(5, query("/i\\j"));
|
assertEquals(5, query("/i\\j"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We pass quotations as-is
|
* We pass quotations as-is
|
||||||
*
|
*
|
||||||
@ -134,7 +135,7 @@ public class JSONPointerTest {
|
|||||||
public void quotationHandling() {
|
public void quotationHandling() {
|
||||||
assertEquals(6, query("/k\"l"));
|
assertEquals(6, query("/k\"l"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whitespaceKey() {
|
public void whitespaceKey() {
|
||||||
assertEquals(7, query("/ "));
|
assertEquals(7, query("/ "));
|
||||||
@ -389,4 +390,28 @@ public class JSONPointerTest {
|
|||||||
obj = jsonArray.optQuery(new JSONPointer("/a/b/c"));
|
obj = jsonArray.optQuery(new JSONPointer("/a/b/c"));
|
||||||
assertTrue("Expected null", obj == null);
|
assertTrue("Expected null", obj == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When creating a jsonObject we need to parse escaped characters "\\\\"
|
||||||
|
* --> it's the string representation of "\\", so when query'ing via the JSONPointer
|
||||||
|
* we DON'T escape them
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void queryFromJSONObjectUsingPointer0() {
|
||||||
|
String str = "{"+
|
||||||
|
"\"string\\\\\\\\Key\":\"hello world!\","+
|
||||||
|
|
||||||
|
"\"\\\\\":\"slash test\"," +
|
||||||
|
"}"+
|
||||||
|
"}";
|
||||||
|
JSONObject jsonObject = new JSONObject(str);
|
||||||
|
//Summary of issue: When a KEY in the jsonObject is "\\\\" --> it's held
|
||||||
|
// as "\\" which means when querying, we need to use "\\"
|
||||||
|
Object twoBackslahObj = jsonObject.optQuery(new JSONPointer("/\\"));
|
||||||
|
assertEquals("slash test", twoBackslahObj);
|
||||||
|
|
||||||
|
Object fourBackslashObj = jsonObject.optQuery(new JSONPointer("/string\\\\Key"));
|
||||||
|
assertEquals("hello world!", fourBackslashObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user