Add an URL method to remove both query string and fragment identifier
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Sep 2017 16:51:17 +0000 (16:51 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Sep 2017 16:51:17 +0000 (16:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176911

Patch by Youenn Fablet <youenn@apple.com> on 2017-09-15
Reviewed by Alex Christensen.

Source/WebCore:

Covered by existing tests and new API tests.

* Modules/cache/DOMCache.cpp:
(WebCore::DOMCache::retrieveRecords): Using new helper method.
* platform/URL.cpp:
(WebCore::URL::removeQueryAndFragmentIdentifier):
* platform/URL.h:

Source/WebKit:

* NetworkProcess/cache/CacheStorageEngineCache.cpp:
(WebKit::CacheStorage::computeKeyURL):

Tools:

Adding unit test for new URL method as well as modified setQuery and setFragmentIdentifier.

* TestWebKitAPI/Tests/WebCore/URL.cpp:
(TestWebKitAPI::createURL):
(TestWebKitAPI::TEST_F):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/cache/DOMCache.cpp
Source/WebCore/platform/URL.cpp
Source/WebCore/platform/URL.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/URL.cpp

index e281b14..eb0d973 100644 (file)
@@ -1,3 +1,18 @@
+2017-09-15  Youenn Fablet  <youenn@apple.com>
+
+        Add an URL method to remove both query string and fragment identifier
+        https://bugs.webkit.org/show_bug.cgi?id=176911
+
+        Reviewed by Alex Christensen.
+
+        Covered by existing tests and new API tests.
+
+        * Modules/cache/DOMCache.cpp:
+        (WebCore::DOMCache::retrieveRecords): Using new helper method.
+        * platform/URL.cpp:
+        (WebCore::URL::removeQueryAndFragmentIdentifier):
+        * platform/URL.h:
+
 2017-09-15  Andy Estes  <aestes@apple.com>
 
         [Cocoa] Upstream MediaRemote and VideoToolbox WebKitSystemInterface functions
index 5a084e2..e931185 100644 (file)
@@ -423,9 +423,7 @@ void DOMCache::retrieveRecords(const URL& url, WTF::Function<void(std::optional<
     setPendingActivity(this);
 
     URL retrieveURL = url;
-    if (retrieveURL.hasQuery())
-        retrieveURL.setQuery({ });
-    retrieveURL.removeFragmentIdentifier();
+    retrieveURL.removeQueryAndFragmentIdentifier();
 
     m_connection->retrieveRecords(m_identifier, retrieveURL, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
         if (!m_isStopped) {
index 79213a6..8be2ca7 100644 (file)
@@ -870,7 +870,16 @@ void URL::removeFragmentIdentifier()
     if (m_isValid && m_string.length() > m_queryEnd)
         m_string = m_string.left(m_queryEnd);
 }
-    
+
+void URL::removeQueryAndFragmentIdentifier()
+{
+    if (!m_isValid)
+        return;
+
+    m_string = m_string.left(m_pathEnd);
+    m_queryEnd = m_pathEnd;
+}
+
 void URL::setQuery(const String& query)
 {
     if (!m_isValid)
index 8be0b16..29c2ae4 100644 (file)
@@ -163,9 +163,11 @@ public:
     // URL (with nothing after it). To clear the query, pass a null string.
     WEBCORE_EXPORT void setQuery(const String&);
 
-    void setFragmentIdentifier(StringView);
+    WEBCORE_EXPORT void setFragmentIdentifier(StringView);
     WEBCORE_EXPORT void removeFragmentIdentifier();
 
+    WEBCORE_EXPORT void removeQueryAndFragmentIdentifier();
+
     WEBCORE_EXPORT friend bool equalIgnoringFragmentIdentifier(const URL&, const URL&);
 
     WEBCORE_EXPORT friend bool protocolHostAndPortAreEqual(const URL&, const URL&);
index 5cdbad2..67b0c82 100644 (file)
@@ -1,3 +1,13 @@
+2017-09-15  Youenn Fablet  <youenn@apple.com>
+
+        Add an URL method to remove both query string and fragment identifier
+        https://bugs.webkit.org/show_bug.cgi?id=176911
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/cache/CacheStorageEngineCache.cpp:
+        (WebKit::CacheStorage::computeKeyURL):
+
 2017-09-15  Andy Estes  <aestes@apple.com>
 
         [Cocoa] Upstream MediaRemote and VideoToolbox WebKitSystemInterface functions
index 82f85bf..e9b1e5a 100644 (file)
@@ -56,11 +56,9 @@ static std::optional<std::pair<Record, double>> decodeRecordHeader(const Storage
 
 static inline String computeKeyURL(const URL& url)
 {
-    URL keyURL = url;
-    if (keyURL.hasQuery())
-        keyURL.setQuery({ });
-    keyURL.removeFragmentIdentifier();
-    return keyURL;
+    URL keyURL { url };
+    keyURL.removeQueryAndFragmentIdentifier();
+    return keyURL.string();
 }
 
 static inline Vector<uint64_t> queryCache(const Vector<RecordInformation>* records, const ResourceRequest& request, const CacheQueryOptions& options)
index 0cdca62..7dd405c 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-15  Youenn Fablet  <youenn@apple.com>
+
+        Add an URL method to remove both query string and fragment identifier
+        https://bugs.webkit.org/show_bug.cgi?id=176911
+
+        Reviewed by Alex Christensen.
+
+        Adding unit test for new URL method as well as modified setQuery and setFragmentIdentifier.
+
+        * TestWebKitAPI/Tests/WebCore/URL.cpp:
+        (TestWebKitAPI::createURL):
+        (TestWebKitAPI::TEST_F):
+
 2017-09-14  Yousuke Kimoto  <yousuke.kimoto@sony.com>
 
         [WinCairo] Add an option to build WebKitLegacy and WebKit
index 30a7e30..180132f 100644 (file)
@@ -71,13 +71,14 @@ TEST_F(URLTest, URLConstructorConstChar)
     EXPECT_EQ(String("fragment"), kurl.fragmentIdentifier());
 }
 
-TEST_F(URLTest, URLProtocolHostAndPort)
+static URL createURL(const char* urlAsString)
 {
-    auto createURL = [](const char* urlAsString) {
-        URLParser parser(urlAsString);
-        return parser.result();
-    };
+    URLParser parser(urlAsString);
+    return parser.result();
+};
 
+TEST_F(URLTest, URLProtocolHostAndPort)
+{
     auto url = createURL("http://username:password@www.example.com:8080/index.html?var=val#fragment");
     EXPECT_EQ(String("http://www.example.com:8080"), url.protocolHostAndPort());
 
@@ -127,4 +128,89 @@ TEST_F(URLTest, URLDataURIStringSharing)
     EXPECT_EQ(threeApples.impl(), url.string().impl());
 }
 
+TEST_F(URLTest, URLSetQuery)
+{
+    URL url = createURL("http://www.webkit.org/?test");
+    URL url1 = createURL("http://www.webkit.org/");
+    URL url2 = createURL("http://www.webkit.org/?");
+    URL url3 = createURL("http://www.webkit.org/?test");
+    URL url4 = createURL("http://www.webkit.org/?test1");
+
+    url1.setQuery("test");
+    url2.setQuery("test");
+    url3.setQuery("test");
+    url4.setQuery("test");
+
+    EXPECT_EQ(url.string(), url1.string());
+    EXPECT_EQ(url.string(), url2.string());
+    EXPECT_EQ(url.string(), url3.string());
+    EXPECT_EQ(url.string(), url4.string());
+
+    URL urlWithFragmentIdentifier = createURL("http://www.webkit.org/?test%C3%83%C2%A5#newFragment");
+    URL urlWithFragmentIdentifier1 = createURL("http://www.webkit.org/#newFragment");
+    URL urlWithFragmentIdentifier2 = createURL("http://www.webkit.org/?#newFragment");
+    URL urlWithFragmentIdentifier3 = createURL("http://www.webkit.org/?test1#newFragment");
+
+    urlWithFragmentIdentifier1.setQuery("test\xc3\xa5");
+    urlWithFragmentIdentifier2.setQuery("test\xc3\xa5");
+    urlWithFragmentIdentifier3.setQuery("test\xc3\xa5");
+
+    EXPECT_EQ(urlWithFragmentIdentifier.string(), urlWithFragmentIdentifier1.string());
+    EXPECT_EQ(urlWithFragmentIdentifier.string(), urlWithFragmentIdentifier2.string());
+    EXPECT_EQ(urlWithFragmentIdentifier.string(), urlWithFragmentIdentifier3.string());
+}
+
+TEST_F(URLTest, URLSetFragmentIdentifier)
+{
+    URL url = createURL("http://www.webkit.org/#newFragment%C3%83%C2%A5");
+    URL url1 = createURL("http://www.webkit.org/");
+    URL url2 = createURL("http://www.webkit.org/#test2");
+    URL url3 = createURL("http://www.webkit.org/#");
+
+    url1.setFragmentIdentifier("newFragment\xc3\xa5");
+    url2.setFragmentIdentifier("newFragment\xc3\xa5");
+    url3.setFragmentIdentifier("newFragment\xc3\xa5");
+
+    EXPECT_EQ(url.string(), url1.string());
+    EXPECT_EQ(url.string(), url2.string());
+    EXPECT_EQ(url.string(), url3.string());
+
+    URL urlWithQuery = createURL("http://www.webkit.org/?test1#newFragment");
+    URL urlWithQuery1 = createURL("http://www.webkit.org/?test1");
+    URL urlWithQuery2 = createURL("http://www.webkit.org/?test1#");
+    URL urlWithQuery3 = createURL("http://www.webkit.org/?test1#test2");
+
+    urlWithQuery1.setFragmentIdentifier("newFragment");
+    urlWithQuery2.setFragmentIdentifier("newFragment");
+    urlWithQuery3.setFragmentIdentifier("newFragment");
+
+    EXPECT_EQ(urlWithQuery.string(), urlWithQuery1.string());
+    EXPECT_EQ(urlWithQuery.string(), urlWithQuery2.string());
+    EXPECT_EQ(urlWithQuery.string(), urlWithQuery3.string());
+}
+
+TEST_F(URLTest, URLRemoveQueryAndFragmentIdentifier)
+{
+    URL url = createURL("http://www.webkit.org/");
+    URL url1 = createURL("http://www.webkit.org/?");
+    URL url2 = createURL("http://www.webkit.org/?test1");
+    URL url3 = createURL("http://www.webkit.org/?test1#test2");
+    URL url4 = createURL("http://www.webkit.org/#test2");
+    URL url5 = createURL("http://www.webkit.org/#");
+
+    url.removeQueryAndFragmentIdentifier();
+    url1.removeQueryAndFragmentIdentifier();
+    url2.removeQueryAndFragmentIdentifier();
+    url3.removeQueryAndFragmentIdentifier();
+    url4.removeQueryAndFragmentIdentifier();
+    url5.removeQueryAndFragmentIdentifier();
+
+    EXPECT_EQ(url.string(), url.string());
+    EXPECT_EQ(url.string(), url1.string());
+    EXPECT_EQ(url.string(), url2.string());
+    EXPECT_EQ(url.string(), url3.string());
+    EXPECT_EQ(url.string(), url4.string());
+    EXPECT_EQ(url.string(), url5.string());
+}
+
 } // namespace TestWebKitAPI