@@ -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 <; </xml>" ).toString ());
775+ assertEquals ("Can cope <; " , XML .unescape ("Can cope <; " ));
776+
777+ assertEquals ("{\" xml\" :\" Can cope & ;\" }" ,
778+ XML .toJSONObject ("<xml>Can cope & ; </xml>" ).toString ());
779+ assertEquals ("Can cope & ; " , XML .unescape ("Can cope & ; " ));
780+
781+ assertEquals ("{\" xml\" :\" Can cope &;\" }" ,
782+ XML .toJSONObject ("<xml>Can cope &; </xml>" ).toString ());
783+ assertEquals ("Can cope &; " , XML .unescape ("Can cope &; " ));
784+
785+ // unicode entity
786+ assertEquals ("{\" xml\" :\" Can cope 4;\" }" ,
787+ XML .toJSONObject ("<xml>Can cope 4; </xml>" ).toString ());
788+ assertEquals ("Can cope 4; " , XML .unescape ("Can cope 4; " ));
789+
790+ // double escaped
791+ assertEquals ("{\" xml\" :\" Can cope <\" }" ,
792+ XML .toJSONObject ("<xml>Can cope &lt; </xml>" ).toString ());
793+ assertEquals ("Can cope < " , XML .unescape ("Can cope &lt; " ));
794+
795+ assertEquals ("{\" xml\" :\" Can cope 4\" }" ,
796+ XML .toJSONObject ("<xml>Can cope &#x34; </xml>" ).toString ());
797+ assertEquals ("Can cope 4 " , XML .unescape ("Can cope &#x34; " ));
798+
799+ }
767800
768801}
0 commit comments