From f4201cf318cff5fba56d1e1ef687ffb3f1a7d421 Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Mon, 19 Mar 2018 09:34:13 -0400 Subject: [PATCH 1/3] Test cases for issue described in https://github.com/stleary/JSON-java/issues/410. --- src/test/java/org/json/junit/JSONPointerTest.java | 13 +++++++++++++ src/test/resources/jsonpointer-testdoc.json | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONPointerTest.java b/src/test/java/org/json/junit/JSONPointerTest.java index 19dac47..c4a8781 100644 --- a/src/test/java/org/json/junit/JSONPointerTest.java +++ b/src/test/java/org/json/junit/JSONPointerTest.java @@ -62,6 +62,19 @@ public class JSONPointerTest { assertSame(document.get(""), query("/")); } + @Test + public void queryByEmptyKeySubObject() { + assertSame(document.getJSONObject("obj").getJSONObject(""), query("/obj/")); + } + + @Test + public void queryByEmptyKeySubObjectSubOject() { + assertSame( + document.getJSONObject("obj").getJSONObject("").get(""), + query("/obj//") + ); + } + @Test public void slashEscaping() { assertSame(document.get("a/b"), query("/a~1b")); diff --git a/src/test/resources/jsonpointer-testdoc.json b/src/test/resources/jsonpointer-testdoc.json index d58fe82..6c1ce28 100644 --- a/src/test/resources/jsonpointer-testdoc.json +++ b/src/test/resources/jsonpointer-testdoc.json @@ -19,6 +19,7 @@ "another/key" : [ "val" ] - } + }, + "" : { "" : "empty key of an object with an empty key" } } } \ No newline at end of file From 43f3f5e80bb845db09e34ce467c38052b08866cf Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Mon, 19 Mar 2018 09:48:50 -0400 Subject: [PATCH 2/3] Add another test --- src/test/java/org/json/junit/JSONPointerTest.java | 8 ++++++++ src/test/resources/jsonpointer-testdoc.json | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONPointerTest.java b/src/test/java/org/json/junit/JSONPointerTest.java index c4a8781..5ddd089 100644 --- a/src/test/java/org/json/junit/JSONPointerTest.java +++ b/src/test/java/org/json/junit/JSONPointerTest.java @@ -74,6 +74,14 @@ public class JSONPointerTest { query("/obj//") ); } + + @Test + public void queryByEmptyKeySubObjectValue() { + assertSame( + document.getJSONObject("obj").getJSONObject("").get("subKey"), + query("/obj//subKey") + ); + } @Test public void slashEscaping() { diff --git a/src/test/resources/jsonpointer-testdoc.json b/src/test/resources/jsonpointer-testdoc.json index 6c1ce28..657ccdd 100644 --- a/src/test/resources/jsonpointer-testdoc.json +++ b/src/test/resources/jsonpointer-testdoc.json @@ -20,6 +20,9 @@ "val" ] }, - "" : { "" : "empty key of an object with an empty key" } + "" : { + "" : "empty key of an object with an empty key", + "subKey" : "Some other value" + } } } \ No newline at end of file From 3fe4a767e6665d8290eb1359c4a9e2d7a13e4997 Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Tue, 20 Mar 2018 22:15:25 -0400 Subject: [PATCH 3/3] Fixes incorrect syntax for JSONPointer in test. --- src/test/java/org/json/junit/JSONObjectTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 303a19a..5dc31c7 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -667,7 +667,7 @@ public class JSONObjectTest { assertTrue("expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); assertTrue("expected 6 myArray items", ((List)(JsonPath.read(doc, "$.myArray"))).size() == 6); assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/myArray/0"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/myArray/1/"))); + assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/myArray/1"))); assertTrue("expected hello world!", "hello world!".equals(jsonObject.query("/myArray/2"))); assertTrue("expected h\be\tllo w\u1234orld!", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/myArray/3"))); assertTrue("expected 42", Integer.valueOf(42).equals(jsonObject.query("/myArray/4")));