Fix query-only and fragment-only relative URLs when using URLParser
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Sep 2016 00:10:21 +0000 (00:10 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Sep 2016 00:10:21 +0000 (00:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161657

Reviewed by Tim Horton.

Source/WebCore:

Covered by new API tests and progress towards passing the web platform tests when using URLParser.

* platform/URLParser.cpp:
(WebCore::URLParser::parse):

Tools:

* TestWebKitAPI/Tests/WebCore/URLParser.cpp:
(TestWebKitAPI::TEST_F):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/URLParser.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

index 2b9436c..fa42167 100644 (file)
@@ -1,3 +1,15 @@
+2016-09-06  Alex Christensen  <achristensen@webkit.org>
+
+        Fix query-only and fragment-only relative URLs when using URLParser
+        https://bugs.webkit.org/show_bug.cgi?id=161657
+
+        Reviewed by Tim Horton.
+
+        Covered by new API tests and progress towards passing the web platform tests when using URLParser.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::parse):
+
 2016-09-06  Chris Dumez  <cdumez@apple.com>
 
         Add support for input.minLength / textArea.minLength
index 8c617db..39fd682 100644 (file)
@@ -517,11 +517,13 @@ URL URLParser::parse(const String& input, const URL& base, const TextEncoding& e
                 break;
             case '?':
                 copyURLPartsUntil(base, URLPart::PathEnd);
+                m_buffer.append('?');
                 state = State::Query;
                 ++c;
                 break;
             case '#':
                 copyURLPartsUntil(base, URLPart::QueryEnd);
+                m_buffer.append('#');
                 state = State::Fragment;
                 ++c;
                 break;
index 25d00b9..8041acf 100644 (file)
@@ -1,5 +1,15 @@
 2016-09-06  Alex Christensen  <achristensen@webkit.org>
 
+        Fix query-only and fragment-only relative URLs when using URLParser
+        https://bugs.webkit.org/show_bug.cgi?id=161657
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-09-06  Alex Christensen  <achristensen@webkit.org>
+
         Punycode encode non-ascii hosts in URLParser
         https://bugs.webkit.org/show_bug.cgi?id=161655
 
index e08dbc2..1a113ed 100644 (file)
@@ -221,6 +221,14 @@ TEST_F(URLParserTest, ParseRelative)
     checkRelativeURL("test", "file:///path1/path2", {"file", "", "", "", 0, "/path1/test", "", "", "file:///path1/test"});
     checkRelativeURL(wideString(L"http://www.foo。bar.com"), "http://other.com/", {"http", "", "", "www.foo.bar.com", 0, "/", "", "", "http://www.foo.bar.com/"});
     checkRelativeURL(wideString(L"sc://ñ.test/"), "about:blank", {"sc", "", "", "xn--ida.test", 0, "/", "", "", "sc://xn--ida.test/"});
+    checkRelativeURL("#fragment", "http://host/path", {"http", "", "", "host", 0, "/path", "", "fragment", "http://host/path#fragment"});
+    checkRelativeURL("?query", "http://host/path", {"http", "", "", "host", 0, "/path", "query", "", "http://host/path?query"});
+    checkRelativeURL("?query#fragment", "http://host/path", {"http", "", "", "host", 0, "/path", "query", "fragment", "http://host/path?query#fragment"});
+    checkRelativeURL(wideString(L"?β"), "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "%CE%B2", "", "http://example.org/foo/bar?%CE%B2"});
+    checkRelativeURL("?", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar?"});
+    checkRelativeURL("#", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar#"});
+    checkRelativeURL("?#", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar?#"});
+    checkRelativeURL("#?", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "?", "http://example.org/foo/bar#?"});
 }
 
 static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld)
@@ -342,6 +350,9 @@ TEST_F(URLParserTest, ParserDifferences)
     checkURLDifferences("file://[0:a:0:0:b:c:0:0]/path",
         {"file", "", "", "[0:a::b:c:0:0]", 0, "/path", "", "", "file://[0:a::b:c:0:0]/path"},
         {"file", "", "", "[0:a:0:0:b:c:0:0]", 0, "/path", "", "", "file://[0:a:0:0:b:c:0:0]/path"});
+    checkRelativeURLDifferences(wideString(L"#β"), "http://example.org/foo/bar",
+        {"http", "", "", "example.org", 0, "/foo/bar", "", wideString(L"β"), wideString(L"http://example.org/foo/bar#β")},
+        {"http", "", "", "example.org", 0, "/foo/bar", "", "%CE%B2", "http://example.org/foo/bar#%CE%B2"});
 
     // FIXME: This behavior ought to be specified in the standard.
     // With the existing URL::parse, WebKit returns "https:/", Firefox returns "https:///", and Chrome throws an error.