Skip to content

Commit f196975

Browse files
committed
all errors except XML fixed
1 parent db197da commit f196975

File tree

10 files changed

+240
-67
lines changed

10 files changed

+240
-67
lines changed

src/main/java/org/json/JSONObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ of this software and associated documentation files (the "Software"), to deal
3232
import java.lang.reflect.Modifier;
3333
import java.util.Collection;
3434
import java.util.Enumeration;
35-
import java.util.HashMap;
3635
import java.util.Iterator;
36+
import java.util.LinkedHashMap;
3737
import java.util.Locale;
3838
import java.util.Map;
3939
import java.util.ResourceBundle;
@@ -93,7 +93,7 @@ of this software and associated documentation files (the "Software"), to deal
9393
* @author JSON.org
9494
* @version 2012-10-27
9595
*/
96-
public class JSONObject extends HashMap{
96+
public class JSONObject extends LinkedHashMap{
9797

9898
/**
9999
* JSONObject.NULL is equivalent to the value that JavaScript calls null,

src/test/java/org/json/tests/TestCDL.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,45 @@ public void testToString_Quotes()
320320
{
321321
jsonarray = CDL
322322
.toJSONArray("Comma delimited list test, '\"Strip\"Quotes', 'quote, comma', No quotes, 'Single Quotes', \"Double Quotes\"\n1,'2',\"3\"\n,'It is \"good,\"', \"It works.\"\n\n");
323-
323+
324324
string = CDL.toString(jsonarray);
325+
// System.out.println( "\"quote, comma\",\"StripQuotes\",Comma delimited list test\n"
326+
// + "3,2,1\n" + "It works.,\"It is good,\",\n");
325327
assertEquals(
326-
"\"quote, comma\",\"StripQuotes\",Comma delimited list test\n"
327-
+ "3,2,1\n" + "It works.,\"It is good,\",\n",
328+
"Comma delimited list test,\"StripQuotes\",\"quote, comma\"\n" +
329+
"1,2,3\n" +
330+
",\"It is good,\",It works.\n",
328331
string);
332+
//System.out.println([\n {\n \"quote, comma\": \"3\",\n \"\\\"Strip\\\"Quotes\": \"2\",\n \"Comma delimited list test\": \"1\"\n },\n {\n \"quote, comma\": \"It works.\",\n \"\\\"Strip\\\"Quotes\": \"It is \\\"good,\\\"\",\n \"Comma delimited list test\": \"\"\n }\n]);
329333
assertEquals(
330-
"[\n {\n \"quote, comma\": \"3\",\n \"\\\"Strip\\\"Quotes\": \"2\",\n \"Comma delimited list test\": \"1\"\n },\n {\n \"quote, comma\": \"It works.\",\n \"\\\"Strip\\\"Quotes\": \"It is \\\"good,\\\"\",\n \"Comma delimited list test\": \"\"\n }\n]",
334+
"[\n" +
335+
" {\n" +
336+
" \"Comma delimited list test\": \"1\",\n" +
337+
" \"\\\"Strip\\\"Quotes\": \"2\",\n" +
338+
" \"quote, comma\": \"3\"\n" +
339+
" },\n" +
340+
" {\n" +
341+
" \"Comma delimited list test\": \"\",\n" +
342+
" \"\\\"Strip\\\"Quotes\": \"It is \\\"good,\\\"\",\n" +
343+
" \"quote, comma\": \"It works.\"\n" +
344+
" }\n" +
345+
"]",
331346
jsonarray.toString(1));
332347
jsonarray = CDL.toJSONArray(string);
348+
//"[\n {\n \"quote, comma\": \"3\",\n \"StripQuotes\": \"2\",\n \"Comma delimited list test\": \"1\"\n },\n {\n \"quote, comma\": \"It works.\",\n \"StripQuotes\": \"It is good,\",\n \"Comma delimited list test\": \"\"\n }\n]"
333349
assertEquals(
334-
"[\n {\n \"quote, comma\": \"3\",\n \"StripQuotes\": \"2\",\n \"Comma delimited list test\": \"1\"\n },\n {\n \"quote, comma\": \"It works.\",\n \"StripQuotes\": \"It is good,\",\n \"Comma delimited list test\": \"\"\n }\n]",
350+
"[\n" +
351+
" {\n" +
352+
" \"Comma delimited list test\": \"1\",\n" +
353+
" \"StripQuotes\": \"2\",\n" +
354+
" \"quote, comma\": \"3\"\n" +
355+
" },\n" +
356+
" {\n" +
357+
" \"Comma delimited list test\": \"\",\n" +
358+
" \"StripQuotes\": \"It is good,\",\n" +
359+
" \"quote, comma\": \"It works.\"\n" +
360+
" }\n" +
361+
"]",
335362
jsonarray.toString(1));
336363
} catch (JSONException e)
337364
{

src/test/java/org/json/tests/TestCookie.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ public static void testToJsonObject_RandomCookieData()
2828
JSONObject jsonobject = new JSONObject();
2929
jsonobject = Cookie
3030
.toJSONObject("f%oo=blah; secure ;expires = April 24, 2002");
31-
assertEquals("{\n" + " \"expires\": \"April 24, 2002\",\n"
32-
+ " \"name\": \"f%oo\",\n" + " \"secure\": true,\n"
33-
+ " \"value\": \"blah\"\n" + "}", jsonobject.toString(2));
31+
// "{\n" + " \"expires\": \"April 24, 2002\",\n"
32+
// + " \"name\": \"f%oo\",\n" + " \"secure\": true,\n"
33+
// + " \"value\": \"blah\"\n" + "}"
34+
assertEquals("{\n" +
35+
" \"name\": \"f%oo\",\n" +
36+
" \"value\": \"blah\",\n" +
37+
" \"secure\": true,\n" +
38+
" \"expires\": \"April 24, 2002\"\n" +
39+
"}", jsonobject.toString(2));
3440
assertEquals("f%25oo=blah;expires=April 24, 2002;secure",
3541
Cookie.toString(jsonobject));
3642
} catch (JSONException e)

src/test/java/org/json/tests/TestCookieList.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ public void testToJsonObject_RandomCookieList()
2828
{
2929
jsonobject = CookieList
3030
.toJSONObject(" f%oo = b+l=ah ; o;n%40e = t.wo ");
31-
assertEquals("{\n \"o;n@e\": \"t.wo\",\n \"f%oo\": \"b l=ah\"\n}",
31+
//"{\n \"o;n@e\": \"t.wo\",\n \"f%oo\": \"b l=ah\"\n}"
32+
assertEquals("{\n" +
33+
" \"f%oo\": \"b l=ah\",\n" +
34+
" \"o;n@e\": \"t.wo\"\n" +
35+
"}",
3236
jsonobject.toString(2));
33-
assertEquals("o%3bn@e=t.wo;f%25oo=b l%3dah",
37+
assertEquals("f%25oo=b l%3dah;o%3bn@e=t.wo",
3438
CookieList.toString(jsonobject));
3539
} catch (JSONException e)
3640
{
@@ -48,7 +52,7 @@ public void testToJsonObject_NullKey()
4852
jsonobject = CookieList
4953
.toJSONObject(" f%oo = b+l=ah ; o;n%40e = t.wo ");
5054
jsonobject.put("abc", JSONObject.NULL);
51-
assertEquals("o%3bn@e=t.wo;f%25oo=b l%3dah",
55+
assertEquals("f%25oo=b l%3dah;o%3bn@e=t.wo",
5256
CookieList.toString(jsonobject));
5357
} catch (JSONException e)
5458
{

src/test/java/org/json/tests/TestHTTP.java

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ public void testToJsonObject_Request()
2626
{
2727
jsonobject = HTTP
2828
.toJSONObject("GET / HTTP/1.0\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\nAccept-Language: en-us\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)\nHost: www.nokko.com\nConnection: keep-alive\nAccept-encoding: gzip, deflate\n");
29+
//"{\n \"Accept-Language\": \"en-us\",\n \"Request-URI\": \"/\",\n \"Host\": \"www.nokko.com\",\n \"Method\": \"GET\",\n \"Accept-encoding\": \"gzip, deflate\",\n \"User-Agent\": \"Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)\",\n \"HTTP-Version\": \"HTTP/1.0\",\n \"Connection\": \"keep-alive\",\n \"Accept\": \"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\"\n}"
2930
assertEquals(
30-
"{\n \"Accept-Language\": \"en-us\",\n \"Request-URI\": \"/\",\n \"Host\": \"www.nokko.com\",\n \"Method\": \"GET\",\n \"Accept-encoding\": \"gzip, deflate\",\n \"User-Agent\": \"Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)\",\n \"HTTP-Version\": \"HTTP/1.0\",\n \"Connection\": \"keep-alive\",\n \"Accept\": \"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\"\n}",
31+
"{\n" +
32+
" \"Method\": \"GET\",\n" +
33+
" \"Request-URI\": \"/\",\n" +
34+
" \"HTTP-Version\": \"HTTP/1.0\",\n" +
35+
" \"Accept\": \"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\",\n" +
36+
" \"Accept-Language\": \"en-us\",\n" +
37+
" \"User-Agent\": \"Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)\",\n" +
38+
" \"Host\": \"www.nokko.com\",\n" +
39+
" \"Connection\": \"keep-alive\",\n" +
40+
" \"Accept-encoding\": \"gzip, deflate\"\n" +
41+
"}",
3142
jsonobject.toString(2));
3243
assertEquals(
33-
"GET \"/\" HTTP/1.0\r\n"
34-
+ "Accept-Language: en-us\r\n"
35-
+ "Host: www.nokko.com\r\n"
36-
+ "Accept-encoding: gzip, deflate\r\n"
37-
+ "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)\r\n"
38-
+ "Connection: keep-alive\r\n"
39-
+ "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\r\n\r\n",
44+
"GET \"/\" HTTP/1.0\r\n" +
45+
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\r\n" +
46+
"Accept-Language: en-us\r\n" +
47+
"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)\r\n" +
48+
"Host: www.nokko.com\r\n" +
49+
"Connection: keep-alive\r\n" +
50+
"Accept-encoding: gzip, deflate\r\n\r\n",
4051
HTTP.toString(jsonobject));
4152

4253
} catch (Exception e)
@@ -54,16 +65,27 @@ public void testToJsonObject_Response()
5465
{
5566
jsonobject = HTTP
5667
.toJSONObject("HTTP/1.1 200 Oki Doki\nDate: Sun, 26 May 2002 17:38:52 GMT\nServer: Apache/1.3.23 (Unix) mod_perl/1.26\nKeep-Alive: timeout=15, max=100\nConnection: Keep-Alive\nTransfer-Encoding: chunked\nContent-Type: text/html\n");
68+
//"{\n \"Reason-Phrase\": \"Oki Doki\",\n \"Status-Code\": \"200\",\n \"Transfer-Encoding\": \"chunked\",\n \"Date\": \"Sun, 26 May 2002 17:38:52 GMT\",\n \"Keep-Alive\": \"timeout=15, max=100\",\n \"HTTP-Version\": \"HTTP/1.1\",\n \"Content-Type\": \"text/html\",\n \"Connection\": \"Keep-Alive\",\n \"Server\": \"Apache/1.3.23 (Unix) mod_perl/1.26\"\n}"
5769
assertEquals(
58-
"{\n \"Reason-Phrase\": \"Oki Doki\",\n \"Status-Code\": \"200\",\n \"Transfer-Encoding\": \"chunked\",\n \"Date\": \"Sun, 26 May 2002 17:38:52 GMT\",\n \"Keep-Alive\": \"timeout=15, max=100\",\n \"HTTP-Version\": \"HTTP/1.1\",\n \"Content-Type\": \"text/html\",\n \"Connection\": \"Keep-Alive\",\n \"Server\": \"Apache/1.3.23 (Unix) mod_perl/1.26\"\n}",
70+
"{\n" +
71+
" \"HTTP-Version\": \"HTTP/1.1\",\n" +
72+
" \"Status-Code\": \"200\",\n" +
73+
" \"Reason-Phrase\": \"Oki Doki\",\n" +
74+
" \"Date\": \"Sun, 26 May 2002 17:38:52 GMT\",\n" +
75+
" \"Server\": \"Apache/1.3.23 (Unix) mod_perl/1.26\",\n" +
76+
" \"Keep-Alive\": \"timeout=15, max=100\",\n" +
77+
" \"Connection\": \"Keep-Alive\",\n" +
78+
" \"Transfer-Encoding\": \"chunked\",\n" +
79+
" \"Content-Type\": \"text/html\"\n" +
80+
"}",
5981
jsonobject.toString(2));
60-
assertEquals("HTTP/1.1 200 Oki Doki\r\n"
61-
+ "Transfer-Encoding: chunked\r\n"
62-
+ "Date: Sun, 26 May 2002 17:38:52 GMT\r\n"
63-
+ "Keep-Alive: timeout=15, max=100\r\n"
64-
+ "Content-Type: text/html\r\n"
65-
+ "Connection: Keep-Alive\r\n"
66-
+ "Server: Apache/1.3.23 (Unix) mod_perl/1.26\r\n\r\n",
82+
assertEquals("HTTP/1.1 200 Oki Doki\r\n" +
83+
"Date: Sun, 26 May 2002 17:38:52 GMT\r\n" +
84+
"Server: Apache/1.3.23 (Unix) mod_perl/1.26\r\n" +
85+
"Keep-Alive: timeout=15, max=100\r\n" +
86+
"Connection: Keep-Alive\r\n" +
87+
"Transfer-Encoding: chunked\r\n" +
88+
"Content-Type: text/html\r\n\r\n",
6789
HTTP.toString(jsonobject));
6890
} catch (Exception e)
6991
{
@@ -80,7 +102,14 @@ public void testToString_NullKey()
80102
{
81103
jsonobject = new JSONObject("{\n \"Reason-Phrase\": \"Oki Doki\",\n \"Status-Code\": \"200\",\n \"Transfer-Encoding\": \"chunked\",\n \"Date\": \"Sun, 26 May 2002 17:38:52 GMT\",\n \"Keep-Alive\": \"timeout=15, max=100\",\n \"HTTP-Version\": \"HTTP/1.1\",\n \"Content-Type\": \"text/html\",\n \"Connection\": \"Keep-Alive\",\n \"Server\": \"Apache/1.3.23 (Unix) mod_perl/1.26\"\n}");
82104
jsonobject.put("testKey", JSONObject.NULL);
83-
assertEquals("HTTP/1.1 200 Oki Doki\r\nDate: Sun, 26 May 2002 17:38:52 GMT\r\nTransfer-Encoding: chunked\r\nKeep-Alive: timeout=15, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\nServer: Apache/1.3.23 (Unix) mod_perl/1.26\r\n\r\n", HTTP.toString(jsonobject));
105+
//"HTTP/1.1 200 Oki Doki\r\nDate: Sun, 26 May 2002 17:38:52 GMT\r\nTransfer-Encoding: chunked\r\nKeep-Alive: timeout=15, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\nServer: Apache/1.3.23 (Unix) mod_perl/1.26\r\n\r\n"
106+
assertEquals("HTTP/1.1 200 Oki Doki\r\n" +
107+
"Transfer-Encoding: chunked\r\n" +
108+
"Date: Sun, 26 May 2002 17:38:52 GMT\r\n" +
109+
"Keep-Alive: timeout=15, max=100\r\n" +
110+
"Content-Type: text/html\r\n" +
111+
"Connection: Keep-Alive\r\n" +
112+
"Server: Apache/1.3.23 (Unix) mod_perl/1.26\r\n\r\n", HTTP.toString(jsonobject));
84113
} catch (Exception e)
85114
{
86115
fail(e.toString());

src/test/java/org/json/tests/TestJSONArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ public void testToJSONObject()
975975
"bdd", "fdsa", "fds", "ewre", "rer", "gfs"
976976
});
977977
assertEquals(
978-
"{\"gfs\":{\"abc\":\"123\"},\"fdsa\":\"-12\",\"bdd\":\"123\",\"ewre\":-98,\"rer\":[\"abc\"],\"fds\":45}",
978+
"{\"bdd\":\"123\",\"fdsa\":\"-12\",\"fds\":45,\"ewre\":-98,\"rer\":[\"abc\"],\"gfs\":{\"abc\":\"123\"}}",
979979
jsonarray.toJSONObject(names).toString());
980980
assertEquals(null, jsonarray.toJSONObject(new JSONArray()));
981981
assertEquals(null, jsonarray.toJSONObject(null));
@@ -1461,7 +1461,7 @@ public void testPassByRefJSONObject(){
14611461
jsonobject.put("a","old");
14621462
jsonarray.put(jsonobject);
14631463
jsonobject.put("b","new");
1464-
assertEquals("[{\"b\":\"new\",\"a\":\"old\"}]",jsonarray.toString());
1464+
assertEquals("[{\"a\":\"old\",\"b\":\"new\"}]",jsonarray.toString());
14651465
}
14661466

14671467
}

0 commit comments

Comments
 (0)