Reviewed by Darin.
authorap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Dec 2007 10:17:08 +0000 (10:17 +0000)
committerap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Dec 2007 10:17:08 +0000 (10:17 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=16325
        <rdar://problem/5632997> REGRESSION: www.xerox.ru doesn't work

        Test: http/tests/misc/empty-cookie.html

        * platform/mac/CookieJar.mm:
        (WebCore::setCookies): Don't store empty cookies.
        (WebCore::cookies): Filter out empty cookies if we have them, as they could have been set
        with an earlier version of Leopard!

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28515 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/misc/empty-cookie-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/empty-cookie.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/platform/mac/CookieJar.mm

index 4931da2ebb6621b314d40557e11759a3539c30da..7fb1165965e039d014563ad01c7c06e369eb0c9e 100644 (file)
@@ -1,3 +1,13 @@
+2007-12-07  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        http://bugs.webkit.org/show_bug.cgi?id=16325
+        <rdar://problem/5632997> REGRESSION: www.xerox.ru doesn't work
+
+        * http/tests/misc/empty-cookie-expected.txt: Added.
+        * http/tests/misc/empty-cookie.html: Added.
+
 2007-12-06  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Darin.
diff --git a/LayoutTests/http/tests/misc/empty-cookie-expected.txt b/LayoutTests/http/tests/misc/empty-cookie-expected.txt
new file mode 100644 (file)
index 0000000..2e4a8dc
--- /dev/null
@@ -0,0 +1,3 @@
+Test that setting a document.cookie to an empty value has no effect
+
+SUCCESS
diff --git a/LayoutTests/http/tests/misc/empty-cookie.html b/LayoutTests/http/tests/misc/empty-cookie.html
new file mode 100644 (file)
index 0000000..0baae45
--- /dev/null
@@ -0,0 +1,12 @@
+<body>
+<p>Test that setting a document.cookie to an empty value has no effect</p>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.cookie = "";
+document.write(document.cookie ? "FAILURE" : "SUCCESS");
+if (document.cookie)
+    document.write(': "' + document.cookie + '"');
+</script>
+</body>
index 5d29305a636fa7fbcb7127b2f41a895467066d7a..225e18509f3f8eba9f7038da17fe936b2aa81728 100644 (file)
@@ -1,3 +1,17 @@
+2007-12-07  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        http://bugs.webkit.org/show_bug.cgi?id=16325
+        <rdar://problem/5632997> REGRESSION: www.xerox.ru doesn't work
+        
+        Test: http/tests/misc/empty-cookie.html
+
+        * platform/mac/CookieJar.mm:
+        (WebCore::setCookies): Don't store empty cookies.
+        (WebCore::cookies): Filter out empty cookies if we have them, as they could have been set
+        with an earlier version of Leopard!
+
 2007-12-06  Ada Chan  <adachan@apple.com>
 
         Fixed the if statement (ERROR_SUCCESS is 0 and we were actually
index 9117ebc42c07605e21d3c5fc07c84e70f29ec78f..3c9fecb298e2e1d9e2a2036d8c726e83a630d76f 100644 (file)
 #import "BlockExceptions.h"
 #import "PlatformString.h"
 
+#import <wtf/RetainPtr.h>
+
+#ifdef BUILDING_ON_TIGER
+typedef unsigned int NSUInteger;
+#endif
+
 namespace WebCore {
 
 String cookies(const KURL& url)
@@ -38,7 +44,18 @@ String cookies(const KURL& url)
 
     NSURL *URL = url.getNSURL();
     NSArray *cookiesForURL = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:URL];
-    NSDictionary *header = [NSHTTPCookie requestHeaderFieldsWithCookies:cookiesForURL];
+
+    // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would happily store an empty cookie, which would be sent as "Cookie: =".
+    // We have a workaround in setCookies() to prevent that, but we also need to avoid sending cookies that were previously stored.
+    NSUInteger count = [cookiesForURL count];
+    RetainPtr<NSMutableArray> cookiesForURLFilteredCopy(AdoptNS, [[NSMutableArray alloc] initWithCapacity:count]);
+    for (NSUInteger i = 0; i < count; ++i) {
+        NSHTTPCookie *cookie = (NSHTTPCookie *)[cookiesForURL objectAtIndex:i];
+        if ([[cookie name] length] != 0)
+            [cookiesForURLFilteredCopy.get() addObject:cookie];
+    }
+
+    NSDictionary *header = [NSHTTPCookie requestHeaderFieldsWithCookies:cookiesForURLFilteredCopy.get()];
     return [header objectForKey:@"Cookie"];
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -49,6 +66,10 @@ void setCookies(const KURL& url, const KURL& policyBaseURL, const String& cookie
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
+    // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would happily store an empty cookie, which would be sent as "Cookie: =".
+    if (cookieStr.isEmpty())
+        return;
+
     NSURL *URL = url.getNSURL();
     
     // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034>