Skip to content

Commit

Permalink
Merge pull request #79 from johnjaylward/FixXMLUnescape
Browse files Browse the repository at this point in the history
New tests for XML unescaping
  • Loading branch information
stleary authored Aug 27, 2017
2 parents d0e2cf4 + 2713f2e commit af3b7dc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/test/java/org/json/junit/XMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -764,5 +764,38 @@ public void testToJsonXML() {

assertEquals(expectedReverseXml, reverseXml);
}

/**
* test to validate certain conditions of XML unescaping.
*/
@Test
public void testUnescape() {
assertEquals("{\"xml\":\"Can cope <;\"}",
XML.toJSONObject("<xml>Can cope &lt;; </xml>").toString());
assertEquals("Can cope <; ", XML.unescape("Can cope &lt;; "));

assertEquals("{\"xml\":\"Can cope & ;\"}",
XML.toJSONObject("<xml>Can cope &amp; ; </xml>").toString());
assertEquals("Can cope & ; ", XML.unescape("Can cope &amp; ; "));

assertEquals("{\"xml\":\"Can cope &;\"}",
XML.toJSONObject("<xml>Can cope &amp;; </xml>").toString());
assertEquals("Can cope &; ", XML.unescape("Can cope &amp;; "));

// unicode entity
assertEquals("{\"xml\":\"Can cope 4;\"}",
XML.toJSONObject("<xml>Can cope &#x34;; </xml>").toString());
assertEquals("Can cope 4; ", XML.unescape("Can cope &#x34;; "));

// double escaped
assertEquals("{\"xml\":\"Can cope &lt;\"}",
XML.toJSONObject("<xml>Can cope &amp;lt; </xml>").toString());
assertEquals("Can cope &lt; ", XML.unescape("Can cope &amp;lt; "));

assertEquals("{\"xml\":\"Can cope &#x34;\"}",
XML.toJSONObject("<xml>Can cope &amp;#x34; </xml>").toString());
assertEquals("Can cope &#x34; ", XML.unescape("Can cope &amp;#x34; "));

}

}

0 comments on commit af3b7dc

Please sign in to comment.