Skip to content

Commit 3e3951f

Browse files
Bad XML
1 parent 90e62b0 commit 3e3951f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Test.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ of this software and associated documentation files (the "Software"), to deal
3535
/**
3636
* Test class. This file is not formally a member of the org.json library.
3737
* It is just a test tool.
38-
*
38+
*
3939
* Issue: JSONObject does not specify the ordering of keys, so simple-minded
4040
* comparisons of .toString to a string literal are likely to fail.
4141
*
4242
* @author JSON.org
43-
* @version 2011-10-03
43+
* @version 2011-10-05
4444
*/
4545
public class Test extends TestCase {
4646
public Test(String name) {
@@ -81,7 +81,7 @@ public void testNull() throws Exception {
8181
}
8282

8383
public void testJSON() throws Exception {
84-
double eps = 2.220446049250313e-16;
84+
double eps = 2.220446049250313e-16;
8585
Iterator iterator;
8686
JSONArray jsonarray;
8787
JSONObject jsonobject;
@@ -94,7 +94,7 @@ public void testJSON() throws Exception {
9494
string = "[001122334455]";
9595
jsonarray = new JSONArray(string);
9696
assertEquals("[1122334455]", jsonarray.toString());
97-
97+
9898
string = "[00.10]";
9999
jsonarray = new JSONArray(string);
100100
assertEquals("[0.1]", jsonarray.toString());
@@ -158,7 +158,7 @@ public void testJSON() throws Exception {
158158
jsonarray.toString(4));
159159
assertEquals("<div id=\"demo\" class=\"JSONML\"><p>JSONML is a transformation between<b>JSON</b>and<b>XML</b>that preserves ordering of document features.</p><p>JSONML can work with JSON arrays or JSON objects.</p><p>Three<br/>little<br/>words</p></div>",
160160
JSONML.toString(jsonarray));
161-
161+
162162
string = "{\"xmlns:soap\":\"http://www.w3.org/2003/05/soap-envelope\",\"tagName\":\"soap:Envelope\",\"childNodes\":[{\"tagName\":\"soap:Header\"},{\"tagName\":\"soap:Body\",\"childNodes\":[{\"tagName\":\"ws:listProducts\",\"childNodes\":[{\"tagName\":\"ws:delay\",\"childNodes\":[1]}]}]}],\"xmlns:ws\":\"http://warehouse.acme.com/ws\"}";
163163
jsonobject = new JSONObject(string);
164164
assertEquals("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ws=\"http://warehouse.acme.com/ws\"><soap:Header/><soap:Body><ws:listProducts><ws:delay>1</ws:delay></ws:listProducts></soap:Body></soap:Envelope>",
@@ -291,7 +291,7 @@ public void testJSON() throws Exception {
291291
jsonarray.put(false);
292292
jsonarray.put(new JSONArray());
293293
jsonarray.put(new JSONObject());
294-
jsonobject.put("keys", JSONObject.getNames(jsonobject));
294+
jsonobject.put("keys", JSONObject.getNames(jsonobject));
295295
assertEquals("{\n \"to\": null,\n \"ten\": 10,\n \"JSONObject\": {},\n \"JSONArray\": [],\n \"op\": \"Good\",\n \"keys\": [\n \"to\",\n \"ten\",\n \"JSONObject\",\n \"JSONArray\",\n \"op\",\n \"int\",\n \"true\",\n \"foo\",\n \"zero\",\n \"double\",\n \"String\",\n \"false\",\n \"bool\",\n \"\\\\u2028\",\n \"\\\\u2029\",\n \"null\"\n ],\n \"int\": 57,\n \"true\": true,\n \"foo\": [\n true,\n false,\n 9876543210,\n 0,\n 1.00000001,\n 1.000000000001,\n 1,\n 1.0E-17,\n 2,\n 0.1,\n 2.0E100,\n -32,\n [],\n {},\n \"string\",\n 666,\n 2001.99,\n \"so \\\"fine\\\".\",\n \"so <fine>.\",\n true,\n false,\n [],\n {}\n ],\n \"zero\": -0,\n \"double\": 1.2345678901234568E29,\n \"String\": \"98.6\",\n \"false\": false,\n \"bool\": \"true\",\n \"\\\\u2028\": \"\\u2028\",\n \"\\\\u2029\": \"\\u2029\",\n \"null\": null\n}",
296296
jsonobject.toString(4));
297297
assertEquals("<to>null</to><ten>10</ten><JSONObject></JSONObject><op>Good</op><keys>to</keys><keys>ten</keys><keys>JSONObject</keys><keys>JSONArray</keys><keys>op</keys><keys>int</keys><keys>true</keys><keys>foo</keys><keys>zero</keys><keys>double</keys><keys>String</keys><keys>false</keys><keys>bool</keys><keys>\\u2028</keys><keys>\\u2029</keys><keys>null</keys><int>57</int><true>true</true><foo>true</foo><foo>false</foo><foo>9876543210</foo><foo>0.0</foo><foo>1.00000001</foo><foo>1.000000000001</foo><foo>1.0</foo><foo>1.0E-17</foo><foo>2.0</foo><foo>0.1</foo><foo>2.0E100</foo><foo>-32</foo><foo></foo><foo></foo><foo>string</foo><foo>666</foo><foo>2001.99</foo><foo>so &quot;fine&quot;.</foo><foo>so &lt;fine&gt;.</foo><foo>true</foo><foo>false</foo><foo></foo><foo></foo><zero>-0.0</zero><double>1.2345678901234568E29</double><String>98.6</String><false>false</false><bool>true</bool><\\u2028>\u2028</\\u2028><\\u2029>\u2029</\\u2029><null>null</null>",
@@ -544,7 +544,7 @@ public void testJSON() throws Exception {
544544
jsonobject.toString(1));
545545

546546
jsonarray = new JSONArray("[2147483647, 2147483648, 9223372036854775807, 9223372036854775808]");
547-
assertEquals("[\n 2147483647,\n 2147483648,\n 9223372036854775807,\n \"9223372036854775808\"\n]",
547+
assertEquals("[\n 2147483647,\n 2147483648,\n 9223372036854775807,\n \"9223372036854775808\"\n]",
548548
jsonarray.toString(1));
549549

550550
List expectedKeys = new ArrayList(6);
@@ -650,7 +650,7 @@ public void testJSON() throws Exception {
650650

651651
string = "{plist=Apple; AnimalSmells = { pig = piggish; lamb = lambish; worm = wormy; }; AnimalSounds = { pig = oink; lamb = baa; worm = baa; Lisa = \"Why is the worm talking like a lamb?\" } ; AnimalColors = { pig = pink; lamb = black; worm = pink; } } ";
652652
jsonobject = new JSONObject(string);
653-
assertEquals("{\"AnimalColors\":{\"worm\":\"pink\",\"lamb\":\"black\",\"pig\":\"pink\"},\"plist\":\"Apple\",\"AnimalSounds\":{\"worm\":\"baa\",\"Lisa\":\"Why is the worm talking like a lamb?\",\"lamb\":\"baa\",\"pig\":\"oink\"},\"AnimalSmells\":{\"worm\":\"wormy\",\"lamb\":\"lambish\",\"pig\":\"piggish\"}}",
653+
assertEquals("{\"AnimalColors\":{\"worm\":\"pink\",\"lamb\":\"black\",\"pig\":\"pink\"},\"plist\":\"Apple\",\"AnimalSounds\":{\"worm\":\"baa\",\"Lisa\":\"Why is the worm talking like a lamb?\",\"lamb\":\"baa\",\"pig\":\"oink\"},\"AnimalSmells\":{\"worm\":\"wormy\",\"lamb\":\"lambish\",\"pig\":\"piggish\"}}",
654654
jsonobject.toString());
655655

656656
string = " [\"San Francisco\", \"New York\", \"Seoul\", \"London\", \"Seattle\", \"Shanghai\"]";
@@ -660,7 +660,7 @@ public void testJSON() throws Exception {
660660

661661
string = "<a ichi='1' ni='2'><b>The content of b</b> and <c san='3'>The content of c</c><d>do</d><e></e><d>re</d><f/><d>mi</d></a>";
662662
jsonobject = XML.toJSONObject(string);
663-
assertEquals("{\"a\":{\"f\":\"\",\"content\":\"and\",\"d\":[\"do\",\"re\",\"mi\"],\"ichi\":1,\"e\":\"\",\"b\":\"The content of b\",\"c\":{\"content\":\"The content of c\",\"san\":3},\"ni\":2}}",
663+
assertEquals("{\"a\":{\"f\":\"\",\"content\":\"and\",\"d\":[\"do\",\"re\",\"mi\"],\"ichi\":1,\"e\":\"\",\"b\":\"The content of b\",\"c\":{\"content\":\"The content of c\",\"san\":3},\"ni\":2}}",
664664
jsonobject.toString());
665665
assertEquals("<a><f/>and<d>do</d><d>re</d><d>mi</d><ichi>1</ichi><e/><b>The content of b</b><c>The content of c<san>3</san></c><ni>2</ni></a>",
666666
XML.toString(jsonobject));
@@ -838,6 +838,15 @@ public void testExceptions() throws Exception {
838838
assertEquals("Mismatched 'right' and 'wrong' at 15 [character 16 line 1]", jsone.getMessage());
839839
}
840840

841+
try {
842+
string = "This ain't XML.";
843+
jsonarray = JSONML.toJSONArray(string);
844+
System.out.println(jsonarray.toString(4));
845+
fail("expecting JSONException here.");
846+
} catch (JSONException jsone) {
847+
assertEquals("Bad XML at 17 [character 18 line 1]", jsone.getMessage());
848+
}
849+
841850
try {
842851
string = "{\"koda\": true, \"koda\": true}";
843852
jsonobject = new JSONObject(string);

0 commit comments

Comments
 (0)