File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .json ;
22
3+ import java .util .Locale ;
4+
35/*
46Copyright (c) 2002 JSON.org
57
@@ -74,7 +76,9 @@ public static String escape(String string) {
7476 * The name will be stored under the key "name", and the value will be
7577 * stored under the key "value". This method does not do checking or
7678 * validation of the parameters. It only converts the cookie string into
77- * a JSONObject.
79+ * a JSONObject. All attribute names are converted to lower case keys in the
80+ * JSONObject (HttpOnly => httponly). If an attribute is specified more than
81+ * once, only the value found closer to the end of the cookie-string is kept.
7882 * @param string The cookie specification string.
7983 * @return A JSONObject containing "name", "value", and possibly other
8084 * members.
@@ -104,7 +108,7 @@ public static JSONObject toJSONObject(String string) {
104108 x .next ();
105109 // parse the remaining cookie attributes
106110 while (x .more ()) {
107- name = unescape (x .nextTo ("=;" )).trim ();
111+ name = unescape (x .nextTo ("=;" )).trim (). toLowerCase ( Locale . ROOT ) ;
108112 // don't allow a cookies attributes to overwrite it's name or value.
109113 if ("name" .equalsIgnoreCase (name )) {
110114 throw new JSONException ("Illegal attribute name: 'name'" );
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public void booleanAttribute() {
8484 JSONObject jo = Cookie .toJSONObject (cookieStr );
8585 assertTrue ("has key 'name'" , jo .has ("name" ));
8686 assertTrue ("has key 'value'" , jo .has ("value" ));
87- assertTrue ("has key 'myAttribute'" , jo .has ("myAttribute " ));
87+ assertTrue ("has key 'myAttribute'" , jo .has ("myattribute " ));
8888 }
8989
9090 /**
@@ -177,7 +177,7 @@ public void convertCookieToString() {
177177 "thisWont=beIncluded;" +
178178 "secure" ;
179179 String expectedCookieStr =
180- "{\" thisWont \" :\" beIncluded\" ," +
180+ "{\" thiswont \" :\" beIncluded\" ," +
181181 "\" path\" :\" /\" ," +
182182 "\" expires\" :\" Wed, 19-Mar-2014 17:53:53 GMT\" ," +
183183 "\" domain\" :\" .yahoo.com\" ," +
You can’t perform that action at this time.
0 commit comments