From cb61bbf720253b2d93832544b189d0a78501c604 Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Sat, 19 Aug 2017 18:19:22 -0400 Subject: [PATCH 1/2] New tests for XML unescaping --- src/test/java/org/json/junit/XMLTest.java | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java index 244c9e9..5daca5c 100644 --- a/src/test/java/org/json/junit/XMLTest.java +++ b/src/test/java/org/json/junit/XMLTest.java @@ -764,5 +764,29 @@ public void testToJsonXML() { assertEquals(expectedReverseXml, reverseXml); } + + /** + * test to validate certain conditions of XML unescaping. + */ + @Test + public void testUnescape() { + assertEquals("{\"xml\":\"Can cope <;\"}", + XML.toJSONObject("Can cope <; ").toString()); + assertEquals("Can cope <; ", XML.unescape("Can cope <; ")); + + assertEquals("{\"xml\":\"Can cope & ;\"}", + XML.toJSONObject("Can cope & ; ").toString()); + assertEquals("Can cope & ; ", XML.unescape("Can cope & ; ")); + + assertEquals("{\"xml\":\"Can cope &;\"}", + XML.toJSONObject("Can cope &; ").toString()); + assertEquals("Can cope &; ", XML.unescape("Can cope &; ")); + + // double escaped + assertEquals("{\"xml\":\"Can cope <\"}", + XML.toJSONObject("Can cope &lt; ").toString()); + assertEquals("Can cope < ", XML.unescape("Can cope &lt; ")); + + } } \ No newline at end of file From 2713f2e2a4a5fa93cdf47b4f926ff5ea088abe68 Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Sat, 19 Aug 2017 18:45:53 -0400 Subject: [PATCH 2/2] Adds testing for unicode entities --- src/test/java/org/json/junit/XMLTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java index 5daca5c..c34bf0f 100644 --- a/src/test/java/org/json/junit/XMLTest.java +++ b/src/test/java/org/json/junit/XMLTest.java @@ -782,11 +782,20 @@ public void testUnescape() { XML.toJSONObject("Can cope &; ").toString()); assertEquals("Can cope &; ", XML.unescape("Can cope &; ")); + // unicode entity + assertEquals("{\"xml\":\"Can cope 4;\"}", + XML.toJSONObject("Can cope 4; ").toString()); + assertEquals("Can cope 4; ", XML.unescape("Can cope 4; ")); + // double escaped assertEquals("{\"xml\":\"Can cope <\"}", XML.toJSONObject("Can cope &lt; ").toString()); assertEquals("Can cope < ", XML.unescape("Can cope &lt; ")); - } + assertEquals("{\"xml\":\"Can cope 4\"}", + XML.toJSONObject("Can cope &#x34; ").toString()); + assertEquals("Can cope 4 ", XML.unescape("Can cope &#x34; ")); + + } } \ No newline at end of file