From 040a8153c7918f1a0f5a50a2cb45d4cc515e43fa Mon Sep 17 00:00:00 2001 From: Christian Biesinger Date: Mon, 11 Apr 2011 16:26:11 -0700 Subject: [PATCH] bug 643051 - document.cookie should only allow setting one cookie at a time r=bz --- content/base/test/test_CrossSiteXHR.html | 5 +++ content/html/content/test/Makefile.in | 1 + content/html/content/test/test_bug643051.html | 43 +++++++++++++++++++ netwerk/cookie/nsCookieService.cpp | 6 ++- netwerk/cookie/test/unit/test_bug643051.js | 25 +++++++++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 content/html/content/test/test_bug643051.html create mode 100644 netwerk/cookie/test/unit/test_bug643051.js diff --git a/content/base/test/test_CrossSiteXHR.html b/content/base/test/test_CrossSiteXHR.html index fd8ea554819..df5abb8c325 100644 --- a/content/base/test/test_CrossSiteXHR.html +++ b/content/base/test/test_CrossSiteXHR.html @@ -842,6 +842,11 @@ function runTest() { } } + // Make sure to clear cookies to avoid affecting other tests + document.cookie = "a=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT" + is(document.cookie, "", "No cookies should be left over"); + + // Test redirects is(loader.src, "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html"); is(origin, "http://example.org"); diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 8e9f031aca6..e03863e859d 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -260,6 +260,7 @@ _TEST_FILES = \ test_bug610212.html \ test_bug633058.html \ test_bug641219.html \ + test_bug643051.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/content/html/content/test/test_bug643051.html b/content/html/content/test/test_bug643051.html new file mode 100644 index 00000000000..08f8cea3266 --- /dev/null +++ b/content/html/content/test/test_bug643051.html @@ -0,0 +1,43 @@ + + + + + Test for Bug 643051 + + + + + +Mozilla Bug 643051 +

+ +
+
+
+ + diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index a1d483a1657..0e67615ce09 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -1550,7 +1550,11 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, // process each cookie in the header nsDependentCString cookieHeader(aCookieHeader); while (SetCookieInternal(aHostURI, baseDomain, requireHostMatch, - cookieStatus, cookieHeader, serverTime, aFromHttp)); + cookieStatus, cookieHeader, serverTime, aFromHttp)) { + // document.cookie can only set one cookie at a time + if (!aFromHttp) + break; + } } // notify observers that a cookie was rejected due to the users' prefs. diff --git a/netwerk/cookie/test/unit/test_bug643051.js b/netwerk/cookie/test/unit/test_bug643051.js new file mode 100644 index 00000000000..3b4f4efc149 --- /dev/null +++ b/netwerk/cookie/test/unit/test_bug643051.js @@ -0,0 +1,25 @@ +const Cc = Components.classes; +const Ci = Components.interfaces; + +Components.utils.import("resource://gre/modules/NetUtil.jsm"); + +function run_test() { + let cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService); + + let uri = NetUtil.newURI("http://example.org/"); + + let set = "foo=bar\nbaz=foo"; + let expected = "foo=bar; baz=foo"; + cs.setCookieStringFromHttp(uri, null, null, set, null, null); + + let actual = cs.getCookieStringFromHttp(uri, null, null); + do_check_eq(actual, expected); + + uri = NetUtil.newURI("http://example.com/"); + cs.setCookieString(uri, null, set, null); + + expected = "foo=bar"; + actual = cs.getCookieString(uri, null, null); + do_check_eq(actual, expected); +} +