Skip to content

Commit 5027a28

Browse files
author
John J. Aylward
committed
Adds test for escaping from a JSONObject to XML
1 parent c8563ff commit 5027a28

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.json.junit;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
45
import static org.junit.Assert.assertNotEquals;
56
import static org.junit.Assert.assertTrue;
67

@@ -293,7 +294,19 @@ public void testXmlEscapeToJson(){
293294
compareStringToJSONObject(xmlStr, expectedStr);
294295
compareReaderToJSONObject(xmlStr, expectedStr);
295296
compareFileToJSONObject(xmlStr, expectedStr);
296-
297+
}
298+
299+
/**
300+
* Tests that certain unicode characters are escaped.
301+
*/
302+
@Test
303+
public void testJsonToXmlEscape(){
304+
JSONObject json = new JSONObject("{ \"amount\": \"10,00 €\", \"description\": \"Ação Válida\" }");
305+
String xml = XML.toString(json);
306+
assertFalse("Escaping € failed. Found in XML output.", xml.contains("€"));
307+
assertTrue("Escaping ç failed. Not found in XML output.", xml.contains("ç"));
308+
assertTrue("Escaping ã failed. Not found in XML output.", xml.contains("ã"));
309+
assertTrue("Escaping á failed. Not found in XML output.", xml.contains("á"));
297310
}
298311

299312
/**

0 commit comments

Comments
 (0)