@@ -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