Add SPI to canonicalize NSURLs with WTF::URL
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Apr 2019 18:21:01 +0000 (18:21 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Apr 2019 18:21:01 +0000 (18:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196415
<rdar://problem/44980271>

Patch by Alex Christensen <achristensen@webkit.org> on 2019-04-01
Reviewed by Darin Adler.

Source/WebKitLegacy/mac:

* Misc/WebNSURLExtras.h:
* Misc/WebNSURLExtras.mm:
(-[NSURL _webkit_canonicalize_with_wtf]):
_webkit_canonicalize is old and changing it causes strange bugs like rdar://problem/5315926
Instead, make a new version that uses WTF::URL to canonicalize an NSURL.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitLegacy/mac/URLCanonicalization.mm: Added.
(TestWebKitAPI::TEST):

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

Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/Misc/WebNSURLExtras.h
Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/URLCanonicalization.mm [new file with mode: 0644]

index d19dcda..42e9fdd 100644 (file)
@@ -1,3 +1,17 @@
+2019-04-01  Alex Christensen  <achristensen@webkit.org>
+
+        Add SPI to canonicalize NSURLs with WTF::URL
+        https://bugs.webkit.org/show_bug.cgi?id=196415
+        <rdar://problem/44980271>
+
+        Reviewed by Darin Adler.
+
+        * Misc/WebNSURLExtras.h:
+        * Misc/WebNSURLExtras.mm:
+        (-[NSURL _webkit_canonicalize_with_wtf]):
+        _webkit_canonicalize is old and changing it causes strange bugs like rdar://problem/5315926
+        Instead, make a new version that uses WTF::URL to canonicalize an NSURL.
+
 2019-03-31  Sam Weinig  <weinig@apple.com>
 
         Remove more i386 specific configurations
index 0d73234..ec70ea3 100644 (file)
@@ -60,6 +60,7 @@
 - (BOOL)_web_isEmpty;
 
 - (NSURL *)_webkit_canonicalize;
+- (NSURL *)_webkit_canonicalize_with_wtf;
 - (NSURL *)_webkit_URLByRemovingFragment;
 - (NSURL *)_web_URLByRemovingUserInfo;
 
index c13b757..c26c97f 100644 (file)
@@ -133,6 +133,12 @@ using namespace WTF;
     return URLByCanonicalizingURL(self);
 }
 
+- (NSURL *)_webkit_canonicalize_with_wtf
+{
+    auto url = WTF::URL(self);
+    return url.isValid() ? (NSURL *)url : nil;
+}
+
 - (NSURL *)_webkit_URLByRemovingFragment 
 {
     return URLByTruncatingOneCharacterBeforeComponent(self, kCFURLComponentFragment);
index 507b726..002e669 100644 (file)
@@ -1,3 +1,15 @@
+2019-04-01  Alex Christensen  <achristensen@webkit.org>
+
+        Add SPI to canonicalize NSURLs with WTF::URL
+        https://bugs.webkit.org/show_bug.cgi?id=196415
+        <rdar://problem/44980271>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitLegacy/mac/URLCanonicalization.mm: Added.
+        (TestWebKitAPI::TEST):
+
 2019-04-01  Zan Dobersek  <zdobersek@igalia.com>
 
         [WPE] EventSenderProxy constructor is called before a PlatformWindow is usable
index 9d55759..d2eb0ab 100644 (file)
                5C2936961D5C00ED00DEAB1E /* CookieMessage.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5C2936941D5BFD1900DEAB1E /* CookieMessage.html */; };
                5C4A84951F7EEFFC00ACFC54 /* Configuration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C4A84941F7EEFD400ACFC54 /* Configuration.mm */; };
                5C69BDD51F82A7EF000F4F4B /* JavaScriptDuringNavigation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C69BDD41F82A7EB000F4F4B /* JavaScriptDuringNavigation.mm */; };
+               5C6E27A7224EEBEA00128736 /* URLCanonicalization.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */; };
                5C7148952123A40A00FDE3C5 /* WKWebsiteDatastore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C7148942123A40700FDE3C5 /* WKWebsiteDatastore.mm */; };
                5C75716122124C5200B9E5AC /* BundleRetainPagePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C75715F221249BD00B9E5AC /* BundleRetainPagePlugIn.mm */; };
                5C7964101EB0278D0075D74C /* EventModifiers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C79640F1EB0269B0075D74C /* EventModifiers.cpp */; };
                5C4A84941F7EEFD400ACFC54 /* Configuration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Configuration.mm; sourceTree = "<group>"; };
                5C5E633D1D0B67940085A025 /* UniqueRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueRef.cpp; sourceTree = "<group>"; };
                5C69BDD41F82A7EB000F4F4B /* JavaScriptDuringNavigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JavaScriptDuringNavigation.mm; sourceTree = "<group>"; };
+               5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = URLCanonicalization.mm; sourceTree = "<group>"; };
                5C7148942123A40700FDE3C5 /* WKWebsiteDatastore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebsiteDatastore.mm; sourceTree = "<group>"; };
                5C75715F221249BD00B9E5AC /* BundleRetainPagePlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BundleRetainPagePlugIn.mm; sourceTree = "<group>"; };
                5C79640F1EB0269B0075D74C /* EventModifiers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventModifiers.cpp; sourceTree = "<group>"; };
                        children = (
                                9BD5111B1FE8E11600D2B630 /* AccessingPastedImage.mm */,
                                6B306105218A372900F5A802 /* ClosingWebView.mm */,
+                               5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                57152B7821DD4E8D000C37CA /* U2fCommandConstructorTest.cpp in Sources */,
                                5CB40B4E1F4B98D3007DC7B9 /* UIDelegate.mm in Sources */,
                                F46849BE1EEF58E400B937FE /* UIPasteboardTests.mm in Sources */,
+                               5C6E27A7224EEBEA00128736 /* URLCanonicalization.mm in Sources */,
                                E3A1E77F21B25B39008C6007 /* URLParserTextEncoding.cpp in Sources */,
                                7CCE7F271A411AF600447C4C /* UserContentController.mm in Sources */,
                                7CCE7F2D1A411B1000447C4C /* UserContentTest.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/URLCanonicalization.mm b/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/URLCanonicalization.mm
new file mode 100644 (file)
index 0000000..bc9a92b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "Test.h"
+#import <WebKit/WebNSURLExtras.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, URLCanonicalization)
+{
+    NSURL *url = [NSURL URLWithString:@"http://a@/"];
+    EXPECT_NOT_NULL(url);
+    EXPECT_NULL([url _webkit_canonicalize_with_wtf]);
+}
+
+} // namespace TestWebKitAPI