Title: [267964] trunk
Revision
267964
Author
achristen...@apple.com
Date
2020-10-05 07:43:04 -0700 (Mon, 05 Oct 2020)

Log Message

When appending a Windows drive letter to a file URL, remove any path we may have copied from the base URL
https://bugs.webkit.org/show_bug.cgi?id=217284

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/url/a-element-expected.txt:
* web-platform-tests/url/a-element-xhtml-expected.txt:
* web-platform-tests/url/resources/urltestdata.json:
* web-platform-tests/url/url-constructor-expected.txt:

Source/WTF:

This fixes a web platform test and adds another to verify that we remove the entire path, not just the last segment like we do with ..
Edge has implemented this, and in order to have a platform-independent URL we should do it too.

* wtf/URLParser.cpp:
(WTF::URLParser::isWindowsDriveLetter):
(WTF::URLParser::appendWindowsDriveLetter):
(WTF::URLParser::parse):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (267963 => 267964)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-10-05 14:40:55 UTC (rev 267963)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-10-05 14:43:04 UTC (rev 267964)
@@ -1,5 +1,17 @@
 2020-10-05  Alex Christensen  <achristen...@webkit.org>
 
+        When appending a Windows drive letter to a file URL, remove any path we may have copied from the base URL
+        https://bugs.webkit.org/show_bug.cgi?id=217284
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/url/a-element-expected.txt:
+        * web-platform-tests/url/a-element-xhtml-expected.txt:
+        * web-platform-tests/url/resources/urltestdata.json:
+        * web-platform-tests/url/url-constructor-expected.txt:
+
+2020-10-05  Alex Christensen  <achristen...@webkit.org>
+
         Fix UTF-8 encoding in URL parsing
         https://bugs.webkit.org/show_bug.cgi?id=217289
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-expected.txt (267963 => 267964)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-expected.txt	2020-10-05 14:40:55 UTC (rev 267963)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-expected.txt	2020-10-05 14:43:04 UTC (rev 267964)
@@ -447,7 +447,8 @@
 PASS Parsing: <file://> against <file://ape/>
 PASS Parsing: </rooibos> against <file://tea/>
 PASS Parsing: </?chai> against <file://tea/>
-FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file://host/C:" but got "file://host/dir/C|"
+PASS Parsing: <C|> against <file://host/dir/file>
+PASS Parsing: <C|> against <file://host/D:/dir1/dir2/file>
 PASS Parsing: <C|#> against <file://host/dir/file>
 PASS Parsing: <C|?> against <file://host/dir/file>
 PASS Parsing: <C|/> against <file://host/dir/file>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-xhtml-expected.txt (267963 => 267964)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-xhtml-expected.txt	2020-10-05 14:40:55 UTC (rev 267963)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-xhtml-expected.txt	2020-10-05 14:43:04 UTC (rev 267964)
@@ -447,7 +447,8 @@
 PASS Parsing: <file://> against <file://ape/>
 PASS Parsing: </rooibos> against <file://tea/>
 PASS Parsing: </?chai> against <file://tea/>
-FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file://host/C:" but got "file://host/dir/C|"
+PASS Parsing: <C|> against <file://host/dir/file>
+PASS Parsing: <C|> against <file://host/D:/dir1/dir2/file>
 PASS Parsing: <C|#> against <file://host/dir/file>
 PASS Parsing: <C|?> against <file://host/dir/file>
 PASS Parsing: <C|/> against <file://host/dir/file>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/url/resources/urltestdata.json (267963 => 267964)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/resources/urltestdata.json	2020-10-05 14:40:55 UTC (rev 267963)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/resources/urltestdata.json	2020-10-05 14:43:04 UTC (rev 267964)
@@ -5684,6 +5684,20 @@
     "hash": ""
   },
   {
+    "input": "C|",
+    "base": "file://host/D:/dir1/dir2/file",
+    "href": "file://host/C:",
+    "protocol": "file:",
+    "username": "",
+    "password": "",
+    "host": "host",
+    "hostname": "host",
+    "port": "",
+    "pathname": "/C:",
+    "search": "",
+    "hash": ""
+  },
+  {
     "input": "C|#",
     "base": "file://host/dir/file",
     "href": "file://host/C:#",

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt (267963 => 267964)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt	2020-10-05 14:40:55 UTC (rev 267963)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt	2020-10-05 14:43:04 UTC (rev 267964)
@@ -448,7 +448,8 @@
 PASS Parsing: <file://> against <file://ape/>
 PASS Parsing: </rooibos> against <file://tea/>
 PASS Parsing: </?chai> against <file://tea/>
-FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file://host/C:" but got "file://host/dir/C|"
+PASS Parsing: <C|> against <file://host/dir/file>
+PASS Parsing: <C|> against <file://host/D:/dir1/dir2/file>
 PASS Parsing: <C|#> against <file://host/dir/file>
 PASS Parsing: <C|?> against <file://host/dir/file>
 PASS Parsing: <C|/> against <file://host/dir/file>

Modified: trunk/Source/WTF/ChangeLog (267963 => 267964)


--- trunk/Source/WTF/ChangeLog	2020-10-05 14:40:55 UTC (rev 267963)
+++ trunk/Source/WTF/ChangeLog	2020-10-05 14:43:04 UTC (rev 267964)
@@ -1,5 +1,20 @@
 2020-10-05  Alex Christensen  <achristen...@webkit.org>
 
+        When appending a Windows drive letter to a file URL, remove any path we may have copied from the base URL
+        https://bugs.webkit.org/show_bug.cgi?id=217284
+
+        Reviewed by Darin Adler.
+
+        This fixes a web platform test and adds another to verify that we remove the entire path, not just the last segment like we do with ..
+        Edge has implemented this, and in order to have a platform-independent URL we should do it too.
+
+        * wtf/URLParser.cpp:
+        (WTF::URLParser::isWindowsDriveLetter):
+        (WTF::URLParser::appendWindowsDriveLetter):
+        (WTF::URLParser::parse):
+
+2020-10-05  Alex Christensen  <achristen...@webkit.org>
+
         Fix UTF-8 encoding in URL parsing
         https://bugs.webkit.org/show_bug.cgi?id=217289
 

Modified: trunk/Source/WTF/wtf/URLParser.cpp (267963 => 267964)


--- trunk/Source/WTF/wtf/URLParser.cpp	2020-10-05 14:40:55 UTC (rev 267963)
+++ trunk/Source/WTF/wtf/URLParser.cpp	2020-10-05 14:43:04 UTC (rev 267964)
@@ -371,16 +371,16 @@
 template<typename CharacterType>
 ALWAYS_INLINE bool URLParser::isWindowsDriveLetter(CodePointIterator<CharacterType> iterator)
 {
+    // https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
     if (iterator.atEnd() || !isASCIIAlpha(*iterator))
         return false;
     advance<CharacterType, ReportSyntaxViolation::No>(iterator);
     if (iterator.atEnd())
         return false;
-    if (*iterator == ':')
-        return true;
-    if (UNLIKELY(*iterator == '|'))
-        return true;
-    return false;
+    if (*iterator != ':' && *iterator != '|')
+        return false;
+    advance<CharacterType, ReportSyntaxViolation::No>(iterator);
+    return iterator.atEnd() || *iterator == '/' || *iterator == '\\' || *iterator == '?' || *iterator == '#';
 }
 
 ALWAYS_INLINE void URLParser::appendToASCIIBuffer(UChar32 codePoint)
@@ -399,6 +399,12 @@
 template<typename CharacterType>
 void URLParser::appendWindowsDriveLetter(CodePointIterator<CharacterType>& iterator)
 {
+    auto lengthWithOnlyOneSlashInPath = m_url.m_hostEnd + m_url.m_portLength + 1;
+    if (m_url.m_pathAfterLastSlash > lengthWithOnlyOneSlashInPath) {
+        syntaxViolation(iterator);
+        m_url.m_pathAfterLastSlash = lengthWithOnlyOneSlashInPath;
+        m_asciiBuffer.resize(lengthWithOnlyOneSlashInPath);
+    }
     ASSERT(isWindowsDriveLetter(iterator));
     appendToASCIIBuffer(*iterator);
     advance(iterator);
@@ -1548,9 +1554,9 @@
                         m_url.m_portLength = 0;
                     }
                     m_url.m_pathAfterLastSlash = m_url.m_hostEnd + 1;
-                    if (isWindowsDriveLetter(c))
-                        appendWindowsDriveLetter(c);
                 }
+                if (isWindowsDriveLetter(c))
+                    appendWindowsDriveLetter(c);
                 state = State::Path;
                 break;
             }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to