Title: [236551] trunk
Revision
236551
Author
[email protected]
Date
2018-09-27 09:34:34 -0700 (Thu, 27 Sep 2018)

Log Message

URLWithUserTypedString should return nil for URLs deemed to be invalid by WebCore::URL
https://bugs.webkit.org/show_bug.cgi?id=189979

Reviewed by Youenn Fablet.

Source/WebCore:

* platform/mac/WebCoreNSURLExtras.mm:
(WebCore::URLWithUserTypedString):
(WebCore::dataForURLComponentType):
(WebCore::URLByRemovingComponentAndSubsequentCharacter):
(WebCore::URLByCanonicalizingURL):
(WebCore::originalURLData):
(WebCore::userVisibleString):

Tools:

* TestWebKitAPI/Tests/WebCore/cocoa/URLExtras.mm:
(TestWebKitAPI::originalDataAsString):
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (236550 => 236551)


--- trunk/Source/WebCore/ChangeLog	2018-09-27 16:31:53 UTC (rev 236550)
+++ trunk/Source/WebCore/ChangeLog	2018-09-27 16:34:34 UTC (rev 236551)
@@ -1,3 +1,18 @@
+2018-09-27  Alex Christensen  <[email protected]>
+
+        URLWithUserTypedString should return nil for URLs deemed to be invalid by WebCore::URL
+        https://bugs.webkit.org/show_bug.cgi?id=189979
+
+        Reviewed by Youenn Fablet.
+
+        * platform/mac/WebCoreNSURLExtras.mm:
+        (WebCore::URLWithUserTypedString):
+        (WebCore::dataForURLComponentType):
+        (WebCore::URLByRemovingComponentAndSubsequentCharacter):
+        (WebCore::URLByCanonicalizingURL):
+        (WebCore::originalURLData):
+        (WebCore::userVisibleString):
+
 2018-09-27  Chris Dumez  <[email protected]>
 
         document.open() should not propagate URLs to non-fully active documents

Modified: trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.mm (236550 => 236551)


--- trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.mm	2018-09-27 16:31:53 UTC (rev 236550)
+++ trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.mm	2018-09-27 16:34:34 UTC (rev 236551)
@@ -895,7 +895,7 @@
 
     // Let's check whether the URL is bogus.
     URL url { URL { nsURL }, string };
-    if (!url.createCFURL())
+    if (!url.isValid() || !url.createCFURL())
         return nil;
 
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=186057
@@ -935,6 +935,8 @@
 
 NSData *dataForURLComponentType(NSURL *URL, CFURLComponentType componentType)
 {
+    if (!URL)
+        return nil;
     Vector<UInt8, URL_BYTES_BUFFER_LENGTH> allBytesBuffer(URL_BYTES_BUFFER_LENGTH);
     CFIndex bytesFilled = CFURLGetBytes((__bridge CFURLRef)URL, allBytesBuffer.data(), allBytesBuffer.size());
     if (bytesFilled == -1) {
@@ -984,6 +986,8 @@
 
 static NSURL *URLByRemovingComponentAndSubsequentCharacter(NSURL *URL, CFURLComponentType component)
 {
+    if (!URL)
+        return nil;
     CFRange range = CFURLGetByteRangeForComponent((__bridge CFURLRef)URL, component, 0);
     if (range.location == kCFNotFound)
         return URL;
@@ -1021,6 +1025,8 @@
 
 NSURL *URLByCanonicalizingURL(NSURL *URL)
 {
+    if (!URL)
+        return nil;
     RetainPtr<NSURLRequest> request = adoptNS([[NSURLRequest alloc] initWithURL:URL]);
     Class concreteClass = [NSURLProtocol _protocolClassForRequest:request.get()];
     if (!concreteClass) {
@@ -1038,6 +1044,8 @@
 
 NSData *originalURLData(NSURL *URL)
 {
+    if (!URL)
+        return nil;
     UInt8 *buffer = (UInt8 *)malloc(URL_BYTES_BUFFER_LENGTH);
     CFIndex bytesFilled = CFURLGetBytes((__bridge CFURLRef)URL, buffer, URL_BYTES_BUFFER_LENGTH);
     if (bytesFilled == -1) {
@@ -1099,6 +1107,8 @@
 
 NSString *userVisibleString(NSURL *URL)
 {
+    if (!URL)
+        return nil;
     NSData *data = ""
     const unsigned char *before = static_cast<const unsigned char*>([data bytes]);
     int length = [data length];

Modified: trunk/Tools/ChangeLog (236550 => 236551)


--- trunk/Tools/ChangeLog	2018-09-27 16:31:53 UTC (rev 236550)
+++ trunk/Tools/ChangeLog	2018-09-27 16:34:34 UTC (rev 236551)
@@ -1,3 +1,14 @@
+2018-09-27  Alex Christensen  <[email protected]>
+
+        URLWithUserTypedString should return nil for URLs deemed to be invalid by WebCore::URL
+        https://bugs.webkit.org/show_bug.cgi?id=189979
+
+        Reviewed by Youenn Fablet.
+
+        * TestWebKitAPI/Tests/WebCore/cocoa/URLExtras.mm:
+        (TestWebKitAPI::originalDataAsString):
+        (TestWebKitAPI::TEST):
+
 2018-09-27  Basuke Suzuki  <[email protected]>
 
         [Win][WebKit] Implement authentication dialog on MiniBrowser.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/URLExtras.mm (236550 => 236551)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/URLExtras.mm	2018-09-27 16:31:53 UTC (rev 236550)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/URLExtras.mm	2018-09-27 16:34:34 UTC (rev 236551)
@@ -50,6 +50,8 @@
 
 static const char* originalDataAsString(NSURL *URL)
 {
+    if (!URL)
+        return "NULL";
     return dataAsString(WebCore::originalURLData(URL));
 }
 
@@ -165,8 +167,8 @@
     // Selected ideographic space, which looks like the ASCII space, which is not allowed unescaped.
 
     // Code path similar to the one used when typing in a URL.
-    EXPECT_STREQ("http://site.com%20othersite.org", originalDataAsString(WebCore::URLWithUserTypedString(@"http://site.com\xE3\x80\x80othersite.org", nil)));
-    EXPECT_STREQ("http://site.com%20othersite.org", userVisibleString(WebCore::URLWithUserTypedString(@"http://site.com\xE3\x80\x80othersite.org", nil)));
+    EXPECT_STREQ("NULL", originalDataAsString(WebCore::URLWithUserTypedString(@"http://site.com\xE3\x80\x80othersite.org", nil)));
+    EXPECT_STREQ(nullptr, userVisibleString(WebCore::URLWithUserTypedString(@"http://site.com\xE3\x80\x80othersite.org", nil)));
 
     // Code paths similar to the ones used for URLs found in webpages or HTTP responses.
     EXPECT_STREQ("http://site.com\xE3\x80\x80othersite.org", originalDataAsString(literalURL("http://site.com\xE3\x80\x80othersite.org")));
@@ -192,6 +194,8 @@
 
     NSString *encodedHostName = WebCore::encodeHostName(@"http://.com");
     EXPECT_TRUE(encodedHostName == nil);
+    
+    EXPECT_TRUE(WebCore::URLWithUserTypedString(@"https://a@/b", nil) == nil);
 }
 
 TEST(WebCore, URLExtras_Nil)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to