From 8ae277735439940480e1301ff729cee32c2ab72e Mon Sep 17 00:00:00 2001 From: Grace Kloba Date: Mon, 3 Aug 2009 17:35:08 -0700 Subject: [PATCH] Fix #2031300. Set only accept unique objects. So we have to assign different value for each cookie when we add them to the SortedSet. --- core/java/android/webkit/CookieManager.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java index c81c4b6a1a715..d188a3986118e 100644 --- a/core/java/android/webkit/CookieManager.java +++ b/core/java/android/webkit/CookieManager.java @@ -197,7 +197,24 @@ public final class CookieManager { private static final class CookieComparator implements Comparator { public int compare(Cookie cookie1, Cookie cookie2) { - return cookie2.path.length() - cookie1.path.length(); + // According to RFC 2109, multiple cookies are ordered in a way such + // that those with more specific Path attributes precede those with + // less specific. Ordering with respect to other attributes (e.g., + // Domain) is unspecified. + // As Set is not modified if the two objects are same, we do want to + // assign different value for each cookie. + int diff = cookie2.path.length() - cookie1.path.length(); + if (diff == 0) { + diff = cookie2.domain.length() - cookie1.domain.length(); + if (diff == 0) { + diff = cookie2.name.hashCode() - cookie1.name.hashCode(); + if (diff == 0) { + Log.w(LOGTAG, "Found two cookies with the same value." + + "cookie1=" + cookie1 + " , cookie2=" + cookie2); + } + } + } + return diff; } }