Skip to content

Commit cb61bbf

Browse files
committed
New tests for XML unescaping
1 parent d0e2cf4 commit cb61bbf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,5 +764,29 @@ 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+
// double escaped
786+
assertEquals("{\"xml\":\"Can cope &lt;\"}",
787+
XML.toJSONObject("<xml>Can cope &amp;lt; </xml>").toString());
788+
assertEquals("Can cope &lt; ", XML.unescape("Can cope &amp;lt; "));
789+
790+
}
767791

768792
}

0 commit comments

Comments
 (0)