Skip to content

Commit 2b87f33

Browse files
author
John J. Aylward
committed
Update test cases to support ISO Control encoding changes.
1 parent 5027a28 commit 2b87f33

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,30 @@ public void testXmlEscapeToJson(){
297297
}
298298

299299
/**
300-
* Tests that certain unicode characters are escaped.
300+
* Tests that control characters are escaped.
301301
*/
302302
@Test
303303
public void testJsonToXmlEscape(){
304-
JSONObject json = new JSONObject("{ \"amount\": \"10,00 €\", \"description\": \"Ação Válida\" }");
304+
final String jsonSrc = "{\"amount\":\"10,00 €\","
305+
+ "\"description\":\"Ação Válida\u0085\","
306+
+ "\"xmlEntities\":\"\\\" ' & < >\""
307+
+ "}";
308+
JSONObject json = new JSONObject(jsonSrc);
305309
String xml = XML.toString(json);
306-
assertFalse("Escaping € failed. Found in XML output.", xml.contains("€"));
310+
//test control character not existing
311+
assertFalse("Escaping \u0085 failed. Found in XML output.", xml.contains("\u0085"));
312+
assertTrue("Escaping \u0085 failed. Entity not found in XML output.", xml.contains("&#x85;"));
313+
// test normal unicode existing
314+
assertTrue("Escaping € failed. Not found in XML output.", xml.contains("€"));
307315
assertTrue("Escaping ç failed. Not found in XML output.", xml.contains("ç"));
308316
assertTrue("Escaping ã failed. Not found in XML output.", xml.contains("ã"));
309317
assertTrue("Escaping á failed. Not found in XML output.", xml.contains("á"));
318+
// test XML Entities converted
319+
assertTrue("Escaping \" failed. Not found in XML output.", xml.contains("&quot;"));
320+
assertTrue("Escaping ' failed. Not found in XML output.", xml.contains("&apos;"));
321+
assertTrue("Escaping & failed. Not found in XML output.", xml.contains("&amp;"));
322+
assertTrue("Escaping < failed. Not found in XML output.", xml.contains("&lt;"));
323+
assertTrue("Escaping > failed. Not found in XML output.", xml.contains("&gt;"));
310324
}
311325

312326
/**

0 commit comments

Comments
 (0)