Skip to content

Commit c8563ff

Browse files
author
John J. Aylward
committed
new test case for XML changes
1 parent 474711c commit c8563ff

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,35 @@ public void shouldHandleSimpleXML() {
267267
compareFileToJSONObject(xmlStr, expectedStr);
268268
}
269269

270+
/**
271+
* Tests to verify that supported escapes in XML are converted to actual values.
272+
*/
273+
@Test
274+
public void testXmlEscapeToJson(){
275+
String xmlStr =
276+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
277+
"<root>"+
278+
"<rawQuote>\"</rawQuote>"+
279+
"<euro>A &#8364;33</euro>"+
280+
"<euroX>A &#x20ac;22&#x20AC;</euroX>"+
281+
"<unknown>some text &copy;</unknown>"+
282+
"<known>&#x0022; &quot; &amp; &apos; &lt; &gt;</known>"+
283+
"</root>";
284+
String expectedStr =
285+
"{\"root\":{" +
286+
"\"rawQuote\":\"\\\"\"," +
287+
"\"euro\":\"A €33\"," +
288+
"\"euroX\":\"A €22€\"," +
289+
"\"unknown\":\"some text &copy;\"," +
290+
"\"known\":\"\\\" \\\" & ' < >\"" +
291+
"}}";
292+
293+
compareStringToJSONObject(xmlStr, expectedStr);
294+
compareReaderToJSONObject(xmlStr, expectedStr);
295+
compareFileToJSONObject(xmlStr, expectedStr);
296+
297+
}
298+
270299
/**
271300
* Valid XML with comments to JSONObject
272301
*/
@@ -675,8 +704,8 @@ public void contentOperations() {
675704
* @param expectedStr the expected JSON string
676705
*/
677706
private void compareStringToJSONObject(String xmlStr, String expectedStr) {
678-
JSONObject expectedJsonObject = new JSONObject(expectedStr);
679707
JSONObject jsonObject = XML.toJSONObject(xmlStr);
708+
JSONObject expectedJsonObject = new JSONObject(expectedStr);
680709
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
681710
}
682711

0 commit comments

Comments
 (0)