Skip to content

Commit 3ed9154

Browse files
committed
fix: refactor tests
context: the backslash unit tests cannot be in the complete document as uriFragmentNotationRoot() will fail due to backslash handling
1 parent 669316d commit 3ed9154

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

src/test/java/org/json/junit/JSONPointerTest.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class JSONPointerTest {
4343
private static final String EXPECTED_COMPLETE_DOCUMENT = "{\"\":0,\" \":7,\"g|h\":4,\"c%d\":2,\"k\\\"l\":6,\"a/b\":1,\"i\\\\j\":5," +
4444
"\"obj\":{\"\":{\"\":\"empty key of an object with an empty key\",\"subKey\":\"Some other value\"}," +
4545
"\"other~key\":{\"another/key\":[\"val\"]},\"key\":\"value\"},\"foo\":[\"bar\",\"baz\"],\"e^f\":3," +
46-
"\"m~n\":8,\"four\\\\\\\\slashes\":\"slash test!\"}";
46+
"\"m~n\":8}";
4747

4848

4949
static {
@@ -125,17 +125,6 @@ public void tildeEscaping() {
125125
public void backslashHandling() {
126126
assertEquals(5, query("/i\\j"));
127127
}
128-
129-
/**
130-
* When creating a jsonObject we need to parse escaped characters "\\\\"
131-
* --> it's the string representation of "\\", so when query'ing via the JSONPointer
132-
* we DON'T escape them
133-
*
134-
*/
135-
@Test
136-
public void multipleBackslashHandling() {
137-
assertEquals("slash test!", query("/four\\\\slashes"));
138-
}
139128

140129
/**
141130
* We pass quotations as-is
@@ -403,8 +392,10 @@ public void optQueryFromJSONArrayUsingPointer() {
403392
}
404393

405394
/**
406-
* KD added - this should pass
407-
* Coverage for JSONObject query(JSONPointer)
395+
* When creating a jsonObject we need to parse escaped characters "\\\\"
396+
* --> it's the string representation of "\\", so when query'ing via the JSONPointer
397+
* we DON'T escape them
398+
*
408399
*/
409400
@Test
410401
public void queryFromJSONObjectUsingPointer0() {
@@ -416,8 +407,11 @@ public void queryFromJSONObjectUsingPointer0() {
416407
"}";
417408
JSONObject jsonObject = new JSONObject(str);
418409
//Summary of issue: When a KEY in the jsonObject is "\\\\" --> it's held
419-
// as "\\" which makes it impossible to get back where expected
420-
Object obj = jsonObject.optQuery(new JSONPointer("/\\"));
421-
assertEquals("slash test", obj);
410+
// as "\\" which means when querying, we need to use "\\"
411+
Object twoBackslahObj = jsonObject.optQuery(new JSONPointer("/\\"));
412+
assertEquals("slash test", twoBackslahObj);
413+
414+
Object fourBackslashObj = jsonObject.optQuery(new JSONPointer("/string\\\\Key"));
415+
assertEquals("hello world!", fourBackslashObj);
422416
}
423417
}

0 commit comments

Comments
 (0)