Title: [99334] trunk/Source/WebCore
Revision
99334
Author
[email protected]
Date
2011-11-04 17:02:45 -0700 (Fri, 04 Nov 2011)

Log Message

[Mac] ResourceRequest's nsURLRequest() does not differentiate null and empty URLs with CFNetwork
https://bugs.webkit.org/show_bug.cgi?id=71539

Patch by Benjamin Poulain <[email protected]> on 2011-11-04
Reviewed by David Kilzer.

In order to have CFURL and NSURL to be consistent when both are used on Mac,
KURL::createCFURL() is changed to support empty URL values.

* platform/cf/KURLCFNet.cpp:
(WebCore::createCFURLFromBuffer):
(WebCore::KURL::createCFURL):
* platform/mac/KURLMac.mm:
(WebCore::KURL::operator NSURL *):
(WebCore::KURL::createCFURL):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (99333 => 99334)


--- trunk/Source/WebCore/ChangeLog	2011-11-04 23:51:23 UTC (rev 99333)
+++ trunk/Source/WebCore/ChangeLog	2011-11-05 00:02:45 UTC (rev 99334)
@@ -1,3 +1,20 @@
+2011-11-04  Benjamin Poulain  <[email protected]>
+
+        [Mac] ResourceRequest's nsURLRequest() does not differentiate null and empty URLs with CFNetwork
+        https://bugs.webkit.org/show_bug.cgi?id=71539
+
+        Reviewed by David Kilzer.
+
+        In order to have CFURL and NSURL to be consistent when both are used on Mac,
+        KURL::createCFURL() is changed to support empty URL values.
+
+        * platform/cf/KURLCFNet.cpp:
+        (WebCore::createCFURLFromBuffer):
+        (WebCore::KURL::createCFURL):
+        * platform/mac/KURLMac.mm:
+        (WebCore::KURL::operator NSURL *):
+        (WebCore::KURL::createCFURL):
+
 2011-11-04  Fady Samuel  <[email protected]>
 
         CSS Aspect Ratio Property Parsing Stage

Modified: trunk/Source/WebCore/platform/cf/KURLCFNet.cpp (99333 => 99334)


--- trunk/Source/WebCore/platform/cf/KURLCFNet.cpp	2011-11-04 23:51:23 UTC (rev 99333)
+++ trunk/Source/WebCore/platform/cf/KURLCFNet.cpp	2011-11-05 00:02:45 UTC (rev 99334)
@@ -33,6 +33,10 @@
 
 namespace WebCore {
 
+typedef Vector<char, 512> CharBuffer;
+
+CFURLRef createCFURLFromBuffer(const CharBuffer&);
+
 KURL::KURL(CFURLRef url)
 {
     if (!url) {
@@ -59,15 +63,8 @@
     parse(buffer.data(), 0);
 }
 
-CFURLRef KURL::createCFURL() const
+CFURLRef createCFURLFromBuffer(const CharBuffer& buffer)
 {
-    // FIXME: What should this return for invalid URLs?
-    // Currently it throws away the high bytes of the characters in the string in that case,
-    // which is clearly wrong.
-
-    Vector<char, 512> buffer;
-    copyToBuffer(buffer);
-
     // NOTE: We use UTF-8 here since this encoding is used when computing strings when returning URL components
     // (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which
     // could either be a malformed string or bytes in a different encoding, like Shift-JIS, so we fall back
@@ -78,6 +75,18 @@
     return result;
 }
 
+#if !PLATFORM(MAC)
+CFURLRef KURL::createCFURL() const
+{
+    // FIXME: What should this return for invalid URLs?
+    // Currently it throws away the high bytes of the characters in the string in that case,
+    // which is clearly wrong.
+    CharBuffer buffer;
+    copyToBuffer(buffer);
+    return createCFURLFromBuffer(buffer);
+}
+#endif
+
 #if !(PLATFORM(QT) && USE(QTKIT))
 String KURL::fileSystemPath() const
 {

Modified: trunk/Source/WebCore/platform/mac/KURLMac.mm (99333 => 99334)


--- trunk/Source/WebCore/platform/mac/KURLMac.mm	2011-11-04 23:51:23 UTC (rev 99333)
+++ trunk/Source/WebCore/platform/mac/KURLMac.mm	2011-11-05 00:02:45 UTC (rev 99334)
@@ -31,6 +31,9 @@
 
 namespace WebCore {
 
+typedef Vector<char, 512> CharBuffer;
+extern CFURLRef createCFURLFromBuffer(const CharBuffer& buffer);
+
 KURL::KURL(NSURL *url)
 {
     if (!url) {
@@ -59,14 +62,22 @@
 
 KURL::operator NSURL *() const
 {
+    return HardAutorelease(createCFURL());
+}
+
+// We use the toll-free bridge between NSURL and CFURL to
+// create a CFURLRef supporting both empty and null values.
+CFURLRef KURL::createCFURL() const
+{
     if (isNull())
-        return nil;
+        return 0;
 
-    // CFURL can't hold an empty URL, unlike NSURL.
     if (isEmpty())
-        return [NSURL URLWithString:@""];
+        return reinterpret_cast<CFURLRef>([[NSURL alloc] initWithString:@""]);
 
-    return HardAutorelease(createCFURL());
+    CharBuffer buffer;
+    copyToBuffer(buffer);
+    return createCFURLFromBuffer(buffer);
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to