Title: [205668] trunk
Revision
205668
Author
[email protected]
Date
2016-09-08 15:16:49 -0700 (Thu, 08 Sep 2016)

Log Message

URLParser should correctly handle \ in path
https://bugs.webkit.org/show_bug.cgi?id=161762

Reviewed by Brady Eidson.

Source/WebCore:

Covered by new API tests.

* platform/URLParser.cpp:
(WebCore::isSpecialScheme):
(WebCore::bufferView):
(WebCore::URLParser::parse):
Treat \ as / in the path of special URLs as described in the spec and tested in web platform tests.
Also a slight performance improvement using StringViews instead of copied Strings.

Tools:

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

Modified Paths

Diff

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


--- trunk/Source/WebCore/ChangeLog	2016-09-08 22:15:07 UTC (rev 205667)
+++ trunk/Source/WebCore/ChangeLog	2016-09-08 22:16:49 UTC (rev 205668)
@@ -1,5 +1,21 @@
 2016-09-08  Alex Christensen  <[email protected]>
 
+        URLParser should correctly handle \ in path
+        https://bugs.webkit.org/show_bug.cgi?id=161762
+
+        Reviewed by Brady Eidson.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::isSpecialScheme):
+        (WebCore::bufferView):
+        (WebCore::URLParser::parse):
+        Treat \ as / in the path of special URLs as described in the spec and tested in web platform tests.
+        Also a slight performance improvement using StringViews instead of copied Strings.
+
+2016-09-08  Alex Christensen  <[email protected]>
+
         URLParser should handle URLs with empty authority
         https://bugs.webkit.org/show_bug.cgi?id=161711
 

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


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-09-08 22:15:07 UTC (rev 205667)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-09-08 22:16:49 UTC (rev 205668)
@@ -139,7 +139,7 @@
     return defaultPorts.get().get(scheme) == port;
 }
 
-static bool isSpecialScheme(const String& scheme)
+static bool isSpecialScheme(StringView scheme)
 {
     return scheme == "ftp"
         || scheme == "file"
@@ -150,6 +150,13 @@
         || scheme == "wss";
 }
 
+static StringView bufferView(const StringBuilder& builder)
+{
+    if (builder.is8Bit())
+        return StringView(builder.characters8(), builder.length());
+    return StringView(builder.characters16(), builder.length());
+}
+
 enum class URLParser::URLPart {
     SchemeEnd,
     UserStart,
@@ -394,6 +401,7 @@
 #define LOG_STATE(x) LOG(URLParser, "State %s, code point %c, buffer length %d", x, *c, m_buffer.length())
 #define LOG_FINAL_STATE(x) LOG(URLParser, "Final State: %s", x)
 
+    bool urlIsSpecial = false;
     State state = State::SchemeStart;
     while (c != end) {
         if (isTabOrNewline(*c)) {
@@ -417,9 +425,10 @@
                 m_buffer.append(toASCIILower(*c));
             else if (*c == ':') {
                 m_url.m_schemeEnd = m_buffer.length();
-                String urlScheme = m_buffer.toString(); // FIXME: Find a way to do this without shrinking the m_buffer.
+                StringView urlScheme = bufferView(m_buffer);
                 m_url.m_protocolIsInHTTPFamily = urlScheme == "http" || urlScheme == "https";
                 if (urlScheme == "file") {
+                    urlIsSpecial = true;
                     state = State::File;
                     m_buffer.append(':');
                     ++c;
@@ -426,6 +435,7 @@
                     break;
                 }
                 if (isSpecialScheme(urlScheme)) {
+                    urlIsSpecial = true;
                     if (base.protocol() == urlScheme)
                         state = State::SpecialRelativeOrAuthority;
                     else
@@ -746,7 +756,7 @@
             break;
         case State::Path:
             LOG_STATE("Path");
-            if (*c == '/') {
+            if (*c == '/' || (urlIsSpecial && *c == '\\')) {
                 m_buffer.append('/');
                 m_url.m_pathAfterLastSlash = m_buffer.length();
                 ++c;

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


--- trunk/Tools/ChangeLog	2016-09-08 22:15:07 UTC (rev 205667)
+++ trunk/Tools/ChangeLog	2016-09-08 22:16:49 UTC (rev 205668)
@@ -1,5 +1,15 @@
 2016-09-08  Alex Christensen  <[email protected]>
 
+        URLParser should correctly handle \ in path
+        https://bugs.webkit.org/show_bug.cgi?id=161762
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-09-08  Alex Christensen  <[email protected]>
+
         URLParser should handle URLs with empty authority
         https://bugs.webkit.org/show_bug.cgi?id=161711
 

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


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-08 22:15:07 UTC (rev 205667)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-08 22:16:49 UTC (rev 205668)
@@ -237,6 +237,8 @@
     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/"});
+    checkRelativeURL("http://foo.com/\\@", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "//@", "", "", "http://foo.com//@"});
+    checkRelativeURL("\\@", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/@", "", "", "http://example.org/@"});
 }
 
 static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to