@@ -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 €33</euro>" +
280+ "<euroX>A €22€</euroX>" +
281+ "<unknown>some text ©</unknown>" +
282+ "<known>" " & ' < ></known>" +
283+ "</root>" ;
284+ String expectedStr =
285+ "{\" root\" :{" +
286+ "\" rawQuote\" :\" \\ \" \" ," +
287+ "\" euro\" :\" A €33\" ," +
288+ "\" euroX\" :\" A €22€\" ," +
289+ "\" unknown\" :\" some text ©\" ," +
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