Title: [205667] trunk
Revision
205667
Author
achristen...@apple.com
Date
2016-09-08 15:15:07 -0700 (Thu, 08 Sep 2016)

Log Message

URLParser should handle URLs with empty authority
https://bugs.webkit.org/show_bug.cgi?id=161711

Reviewed by Brady Eidson.

Source/WebCore:

Covered by new API tests.

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

Tools:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (205666 => 205667)


--- trunk/Source/WebCore/ChangeLog	2016-09-08 22:12:05 UTC (rev 205666)
+++ trunk/Source/WebCore/ChangeLog	2016-09-08 22:15:07 UTC (rev 205667)
@@ -1,3 +1,16 @@
+2016-09-08  Alex Christensen  <achristen...@webkit.org>
+
+        URLParser should handle URLs with empty authority
+        https://bugs.webkit.org/show_bug.cgi?id=161711
+
+        Reviewed by Brady Eidson.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::parse):
+        (WebCore::URLParser::parseAuthority):
+
 2016-09-08  Chris Dumez  <cdu...@apple.com>
 
         HTMLImageElement.hspace / vspace attributes should be unsigned

Modified: trunk/Source/WebCore/platform/URLParser.cpp (205666 => 205667)


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-09-08 22:12:05 UTC (rev 205666)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-09-08 22:15:07 UTC (rev 205667)
@@ -857,7 +857,7 @@
         break;
     case State::SpecialAuthorityIgnoreSlashes:
         LOG_FINAL_STATE("SpecialAuthorityIgnoreSlashes");
-        break;
+        return { };
     case State::AuthorityOrHost:
         LOG_FINAL_STATE("AuthorityOrHost");
         m_url.m_userEnd = m_buffer.length();
@@ -974,13 +974,25 @@
 
 void URLParser::parseAuthority(StringView::CodePoints::Iterator& iterator, const StringView::CodePoints::Iterator& end)
 {
+    if (iterator == end) {
+        m_url.m_userEnd = m_buffer.length();
+        m_url.m_passwordEnd = m_url.m_userEnd;
+        return;
+    }
     for (; iterator != end; ++iterator) {
-        m_buffer.append(*iterator);
         if (*iterator == ':') {
             ++iterator;
-            m_url.m_userEnd = m_buffer.length() - 1;
+            m_url.m_userEnd = m_buffer.length();
+            if (iterator == end) {
+                m_url.m_passwordEnd = m_url.m_userEnd;
+                if (m_url.m_userEnd > m_url.m_userStart)
+                    m_buffer.append('@');
+                return;
+            }
+            m_buffer.append(':');
             break;
         }
+        m_buffer.append(*iterator);
     }
     for (; iterator != end; ++iterator)
         m_buffer.append(*iterator);

Modified: trunk/Tools/ChangeLog (205666 => 205667)


--- trunk/Tools/ChangeLog	2016-09-08 22:12:05 UTC (rev 205666)
+++ trunk/Tools/ChangeLog	2016-09-08 22:15:07 UTC (rev 205667)
@@ -1,5 +1,15 @@
 2016-09-08  Alex Christensen  <achristen...@webkit.org>
 
+        URLParser should handle URLs with empty authority
+        https://bugs.webkit.org/show_bug.cgi?id=161711
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-09-08  Alex Christensen  <achristen...@webkit.org>
+
         Re-land r205580 after r205649 fixed the test failures
         https://bugs.webkit.org/show_bug.cgi?id=161668
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (205666 => 205667)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-08 22:12:05 UTC (rev 205666)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-08 22:15:07 UTC (rev 205667)
@@ -178,6 +178,11 @@
     checkURL("http://host/A b", {"http", "", "", "host", 0, "/A%20b", "", "", "http://host/A%20b"});
     checkURL("http://host/a%20B", {"http", "", "", "host", 0, "/a%20B", "", "", "http://host/a%20B"});
     checkURL("http://host?q=@ <>!#fragment", {"http", "", "", "host", 0, "/", "q=@%20%3C%3E!", "fragment", "http://host/?q=@%20%3C%3E!#fragment"});
+    checkURL("http://user:@host", {"http", "user", "", "host", 0, "/", "", "", "http://user@host/"});
+
+    // This disagrees with the web platform test for http://:@www.example.com but agrees with Chrome and URL::parse,
+    // and Firefox fails the web platform test differently. Maybe the web platform test ought to be changed.
+    checkURL("http://:@host", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
 }
 
 static void checkRelativeURL(const String& urlString, const String& baseURLString, const ExpectedParts& parts)
@@ -230,6 +235,8 @@
     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, "/", "", "", "http://example.org/"});
+    checkRelativeURL("http://@host", "about:blank", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
+    checkRelativeURL("http://:@host", "about:blank", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
 }
 
 static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld)
@@ -354,11 +361,14 @@
     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.
+    checkURLDifferences("http://@",
+        {"", "", "", "", 0, "", "", "", ""},
+        {"", "", "", "", 0, "", "", "", "http://@"});
+    checkURLDifferences("http://",
+        {"", "", "", "", 0, "", "", "", ""},
+        {"http", "", "", "", 0, "/", "", "", "http:/"});
     checkRelativeURLDifferences("//", "https://www.webkit.org/path",
-        {"https", "", "", "", 0, "", "", "", "https://"},
+        {"", "", "", "", 0, "", "", "", ""},
         {"https", "", "", "", 0, "/", "", "", "https:/"});
     
     // This behavior matches Chrome and Firefox, but not WebKit using URL::parse.
@@ -436,6 +446,24 @@
         {"wss", "", "", "host", 444, "", "", "", "wss://host:444"});
     
     // FIXME: Fix and check unknown schemes with ports, as well as ftps.
+
+    // Firefox returns http://a:@/ Chrome fails, URL::parse fails
+    checkRelativeURLDifferences("http://a:@", "about:blank",
+        {"", "", "", "", 0, "", "", "", ""},
+        {"", "", "", "", 0, "", "", "", "http://a:@"});
+    
+    checkRelativeURLDifferences("http://:@", "about:blank",
+        {"", "", "", "", 0, "", "", "", ""},
+        {"", "", "", "", 0, "", "", "", "http://:@"});
+    checkRelativeURLDifferences("http://:b@", "about:blank",
+        {"", "", "", "", 0, "", "", "", ""},
+        {"", "", "", "", 0, "", "", "", "http://:b@"});
+    checkURLDifferences("http://a:@",
+        {"", "", "", "", 0, "", "", "", ""},
+        {"", "", "", "", 0, "", "", "", "http://a:@"});
+    checkURLDifferences("http://:b@",
+        {"", "", "", "", 0, "", "", "", ""},
+        {"", "", "", "", 0, "", "", "", "http://:b@"});
 }
     
 static void shouldFail(const String& urlString)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to