Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ae27773 authored by Grace Kloba's avatar Grace Kloba
Browse files

Fix #2031300. Set only accept unique objects. So we have to assign different

value for each cookie when we add them to the SortedSet.
parent 7a17cf34
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -197,7 +197,24 @@ public final class CookieManager {

    private static final class CookieComparator implements Comparator<Cookie> {
        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;
        }
    }