1
Description: Fix cookie regression from Firefox 3.6.18
2
When talking to an hostname consisting of a single letter, Firefox 3.6.18 does
3
not set cookie. Previous versions did fine, as well as other browser such as
5
Author: Chris Coulson <chris.coulson@canonical.com>
6
Bug-Ubuntu: https://bugs.launchpad.net/bugs/801778
7
Forwarded: https://bugzilla.mozilla.org/show_bug.cgi?id=667087
8
Origin: https://bug667087.bugzilla.mozilla.org/attachment.cgi?id=542125
10
diff --git a/extensions/cookie/test/unit/test_bug667087.js b/extensions/cookie/test/unit/test_bug667087.js
13
+++ b/extensions/cookie/test/unit/test_bug667087.js
15
+/* Any copyright is dedicated to the Public Domain.
16
+ http://creativecommons.org/publicdomain/zero/1.0/ */
18
+const Cc = Components.classes;
19
+const Ci = Components.interfaces;
21
+Components.utils.import("resource://gre/modules/NetUtil.jsm");
23
+function run_test() {
24
+ var cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
25
+ var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
26
+ var expiry = (Date.now() + 1000) * 1000;
28
+ // Test our handling of host names with a single character consisting only
29
+ // of a single character
30
+ cm.add("a", "/", "foo", "bar", false, false, true, expiry);
31
+ do_check_eq(cm.countCookiesFromHost("a"), 1);
32
+ do_check_eq(cs.getCookieString(NetUtil.newURI("http://a"), null), "foo=bar");
34
diff --git a/netwerk/cookie/src/nsCookieService.cpp b/netwerk/cookie/src/nsCookieService.cpp
35
--- a/netwerk/cookie/src/nsCookieService.cpp
36
+++ b/netwerk/cookie/src/nsCookieService.cpp
37
@@ -1343,17 +1343,17 @@ nsCookieService::GetCookieInternal(nsIUR
40
// all checks passed - add to list and check if lastAccessed stamp needs updating
41
foundCookieList.AppendElement(cookie);
42
if (currentTimeInUsec - cookie->LastAccessed() > kCookieStaleThreshold)
46
- if (!nextDot || (nextDot <= end && *(nextDot + 1) == '\0'))
47
+ if (!nextDot || (nextDot <= end && *(nextDot + 1) == '\0' && *nextDot == '.'))
51
nextDot = *currentDot ? strchr(currentDot + 1, '.') : nsnull;
54
PRInt32 count = foundCookieList.Length();
56
@@ -2223,17 +2223,17 @@ nsCookieService::CountCookiesFromHostInt
57
// check if we've found the oldest cookie so far
58
if (aData.oldestTime > iter.current->LastAccessed()) {
59
aData.oldestTime = iter.current->LastAccessed();
65
- if (!nextDot || (nextDot <= end && *(nextDot + 1) == '\0'))
66
+ if (!nextDot || (nextDot <= end && *(nextDot + 1) == '\0' && *nextDot == '.'))
70
nextDot = *currentDot ? strchr(currentDot + 1, '.') : nsnull;
75
@@ -2276,17 +2276,17 @@ nsCookieService::GetCookiesFromHost(cons
77
nsCookieEntry *entry = mDBState->hostTable.GetEntry(currentDot);
78
for (nsListIter iter(entry); iter.current; ++iter) {
79
// only append non-expired cookies
80
if (iter.current->Expiry() > currentTime)
81
cookieList.AppendObject(iter.current);
84
- if (!nextDot || (nextDot <= end && *(nextDot + 1) == '\0'))
85
+ if (!nextDot || (nextDot <= end && *(nextDot + 1) == '\0' && *nextDot == '.'))
89
nextDot = *currentDot ? strchr(currentDot + 1, '.') : nsnull;
92
return NS_NewArrayEnumerator(aEnumerator, cookieList);