URLParser: Correctly parse URLs that are just nonspecialscheme:/
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 18:02:52 +0000 (18:02 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 18:02:52 +0000 (18:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162340

Reviewed by Tim Horton.

Source/WebCore:

Covered by new API tests.

* platform/URLParser.cpp:
(WebCore::URLParser::parse):
r206162 wasn't quite right.  If a url is just nonspecialscheme:/ then the path should indeed be /

Tools:

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

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

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

index 62f9ffd..4f76c8a 100644 (file)
@@ -1,5 +1,18 @@
 2016-09-21  Alex Christensen  <achristensen@webkit.org>
 
+        URLParser: Correctly parse URLs that are just nonspecialscheme:/
+        https://bugs.webkit.org/show_bug.cgi?id=162340
+
+        Reviewed by Tim Horton.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::parse):
+        r206162 wasn't quite right.  If a url is just nonspecialscheme:/ then the path should indeed be /
+
+2016-09-21  Alex Christensen  <achristensen@webkit.org>
+
         URLParser: correctly parse relative URLs that are just one character
         https://bugs.webkit.org/show_bug.cgi?id=162344
 
index 7f47a70..6508690 100644 (file)
@@ -1473,11 +1473,15 @@ URL URLParser::parse(const CharacterType* input, const unsigned length, const UR
         break;
     case State::PathOrAuthority:
         LOG_FINAL_STATE("PathOrAuthority");
-        m_url.m_userEnd = m_asciiBuffer.size();
-        m_url.m_passwordEnd = m_url.m_userEnd;
-        m_url.m_hostEnd = m_url.m_userEnd;
-        m_url.m_portEnd = m_url.m_userEnd;
-        m_url.m_pathAfterLastSlash = m_url.m_userEnd;
+        ASSERT(m_url.m_userStart);
+        ASSERT(m_url.m_userStart == m_asciiBuffer.size());
+        ASSERT(m_asciiBuffer.last() == '/');
+        m_url.m_userStart--;
+        m_url.m_userEnd = m_url.m_userStart;
+        m_url.m_passwordEnd = m_url.m_userStart;
+        m_url.m_hostEnd = m_url.m_userStart;
+        m_url.m_portEnd = m_url.m_userStart;
+        m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
         m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
         m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
         m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
index dcd9141..feb39f4 100644 (file)
@@ -1,5 +1,15 @@
 2016-09-21  Alex Christensen  <achristensen@webkit.org>
 
+        URLParser: Correctly parse URLs that are just nonspecialscheme:/
+        https://bugs.webkit.org/show_bug.cgi?id=162340
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-09-21  Alex Christensen  <achristensen@webkit.org>
+
         URLParser: correctly parse relative URLs that are just one character
         https://bugs.webkit.org/show_bug.cgi?id=162344
 
index 847ae67..74ea8fd 100644 (file)
@@ -215,6 +215,7 @@ TEST_F(URLParserTest, Basic)
     checkURL("http://123.256/", {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});
     checkURL("notspecial:/a", {"notspecial", "", "", "", 0, "/a", "", "", "notspecial:/a"});
     checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
+    checkURL("notspecial:/", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
 
     // 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.
@@ -302,7 +303,10 @@ TEST_F(URLParserTest, ParseRelative)
     checkRelativeURL("i", "sc://ho/pa", {"sc", "", "", "ho", 0, "/i", "", "", "sc://ho/i"});
     checkRelativeURL("!", "sc://ho/pa", {"sc", "", "", "ho", 0, "/!", "", "", "sc://ho/!"});
     checkRelativeURL("!", "sc:/ho/pa", {"sc", "", "", "", 0, "/ho/!", "", "", "sc:/ho/!"});
-    
+    checkRelativeURL("notspecial:/", "about:blank", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
+    checkRelativeURL("notspecial:/", "http://host", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
+    checkRelativeURL("foo:/", "http://example.org/foo/bar", {"foo", "", "", "", 0, "/", "", "", "foo:/"});
+
     // The checking of slashes in SpecialAuthoritySlashes needed to get this to pass contradicts what is in the spec,
     // but it is included in the web platform tests.
     checkRelativeURL("http:\\\\host\\foo", "about:blank", {"http", "", "", "host", 0, "/foo", "", "", "http://host/foo"});
@@ -567,17 +571,6 @@ TEST_F(URLParserTest, ParserDifferences)
     checkURLDifferences(wideString(L"http://host?ß😍#ß😍"),
         {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", wideString(L"ß😍"), wideString(L"http://host/?%C3%9F%F0%9F%98%8D#ß😍")},
         {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", "%C3%9F%F0%9F%98%8D", "http://host/?%C3%9F%F0%9F%98%8D#%C3%9F%F0%9F%98%8D"});
-
-    // This matches the spec and web platform tests, but not Chrome, Firefox, or URL::parse.
-    checkRelativeURLDifferences("notspecial:/", "about:blank",
-        {"notspecial", "", "", "", 0, "", "", "", "notspecial:/"},
-        {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
-    checkRelativeURLDifferences("notspecial:/", "http://host",
-        {"notspecial", "", "", "", 0, "", "", "", "notspecial:/"},
-        {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
-    checkURLDifferences("notspecial:/",
-        {"notspecial", "", "", "", 0, "", "", "", "notspecial:/"},
-        {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
 }
 
 TEST_F(URLParserTest, DefaultPort)