Skip to content

Commit af3b7dc

Browse files
authored
Merge pull request #79 from johnjaylward/FixXMLUnescape
New tests for XML unescaping
2 parents d0e2cf4 + 2713f2e commit af3b7dc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,5 +764,38 @@ public void testToJsonXML() {
764764

765765
assertEquals(expectedReverseXml, reverseXml);
766766
}
767+
768+
/**
769+
* test to validate certain conditions of XML unescaping.
770+
*/
771+
@Test
772+
public void testUnescape() {
773+
assertEquals("{\"xml\":\"Can cope <;\"}",
774+
XML.toJSONObject("<xml>Can cope &lt;; </xml>").toString());
775+
assertEquals("Can cope <; ", XML.unescape("Can cope &lt;; "));
776+
777+
assertEquals("{\"xml\":\"Can cope & ;\"}",
778+
XML.toJSONObject("<xml>Can cope &amp; ; </xml>").toString());
779+
assertEquals("Can cope & ; ", XML.unescape("Can cope &amp; ; "));
780+
781+
assertEquals("{\"xml\":\"Can cope &;\"}",
782+
XML.toJSONObject("<xml>Can cope &amp;; </xml>").toString());
783+
assertEquals("Can cope &; ", XML.unescape("Can cope &amp;; "));
784+
785+
// unicode entity
786+
assertEquals("{\"xml\":\"Can cope 4;\"}",
787+
XML.toJSONObject("<xml>Can cope &#x34;; </xml>").toString());
788+
assertEquals("Can cope 4; ", XML.unescape("Can cope &#x34;; "));
789+
790+
// double escaped
791+
assertEquals("{\"xml\":\"Can cope &lt;\"}",
792+
XML.toJSONObject("<xml>Can cope &amp;lt; </xml>").toString());
793+
assertEquals("Can cope &lt; ", XML.unescape("Can cope &amp;lt; "));
794+
795+
assertEquals("{\"xml\":\"Can cope &#x34;\"}",
796+
XML.toJSONObject("<xml>Can cope &amp;#x34; </xml>").toString());
797+
assertEquals("Can cope &#x34; ", XML.unescape("Can cope &amp;#x34; "));
798+
799+
}
767800

768801
}

0 commit comments

Comments
 (0)