Title: [205684] trunk
Revision
205684
Author
achristen...@apple.com
Date
2016-09-08 18:32:18 -0700 (Thu, 08 Sep 2016)

Log Message

URLParser: Handle \ in paths of special URLs according to spec
https://bugs.webkit.org/show_bug.cgi?id=161781

Reviewed by Tim Horton.

Source/WebCore:

Covered by new API tests.

* platform/URLParser.cpp:
(WebCore::bufferView):
(WebCore::URLParser::copyURLPartsUntil):
(WebCore::URLParser::parse):
* platform/URLParser.h:

Tools:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (205683 => 205684)


--- trunk/Source/WebCore/ChangeLog	2016-09-09 01:22:05 UTC (rev 205683)
+++ trunk/Source/WebCore/ChangeLog	2016-09-09 01:32:18 UTC (rev 205684)
@@ -1,3 +1,18 @@
+2016-09-08  Alex Christensen  <achristen...@webkit.org>
+
+        URLParser: Handle \ in paths of special URLs according to spec
+        https://bugs.webkit.org/show_bug.cgi?id=161781
+
+        Reviewed by Tim Horton.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::bufferView):
+        (WebCore::URLParser::copyURLPartsUntil):
+        (WebCore::URLParser::parse):
+        * platform/URLParser.h:
+
 2016-09-08  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         Move the BitmapImage platform dependent code to a new file named NativeImage[CG|Cairo].cpp

Modified: trunk/Source/WebCore/platform/URLParser.cpp (205683 => 205684)


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-09-09 01:22:05 UTC (rev 205683)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-09-09 01:32:18 UTC (rev 205684)
@@ -150,11 +150,12 @@
         || scheme == "wss";
 }
 
-static StringView bufferView(const StringBuilder& builder)
+static StringView bufferView(const StringBuilder& builder, unsigned length)
 {
+    ASSERT(builder.length() >= length);
     if (builder.is8Bit())
-        return StringView(builder.characters8(), builder.length());
-    return StringView(builder.characters16(), builder.length());
+        return StringView(builder.characters8(), length);
+    return StringView(builder.characters16(), length);
 }
 
 enum class URLParser::URLPart {
@@ -235,6 +236,7 @@
         m_url.m_protocolIsInHTTPFamily = base.m_protocolIsInHTTPFamily;
         m_url.m_schemeEnd = base.m_schemeEnd;
     }
+    m_urlIsSpecial = isSpecialScheme(bufferView(m_buffer, m_url.m_schemeEnd));
 }
 
 static const char* dotASCIICode = "2e";
@@ -420,7 +422,6 @@
 #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)) {
@@ -444,10 +445,10 @@
                 m_buffer.append(toASCIILower(*c));
             else if (*c == ':') {
                 m_url.m_schemeEnd = m_buffer.length();
-                StringView urlScheme = bufferView(m_buffer);
+                StringView urlScheme = bufferView(m_buffer, m_url.m_schemeEnd);
                 m_url.m_protocolIsInHTTPFamily = urlScheme == "http" || urlScheme == "https";
                 if (urlScheme == "file") {
-                    urlIsSpecial = true;
+                    m_urlIsSpecial = true;
                     state = State::File;
                     m_buffer.append(':');
                     ++c;
@@ -454,7 +455,7 @@
                     break;
                 }
                 if (isSpecialScheme(urlScheme)) {
-                    urlIsSpecial = true;
+                    m_urlIsSpecial = true;
                     if (base.protocol() == urlScheme)
                         state = State::SpecialRelativeOrAuthority;
                     else
@@ -775,7 +776,7 @@
             break;
         case State::Path:
             LOG_STATE("Path");
-            if (*c == '/' || (urlIsSpecial && *c == '\\')) {
+            if (*c == '/' || (m_urlIsSpecial && *c == '\\')) {
                 m_buffer.append('/');
                 m_url.m_pathAfterLastSlash = m_buffer.length();
                 ++c;

Modified: trunk/Source/WebCore/platform/URLParser.h (205683 => 205684)


--- trunk/Source/WebCore/platform/URLParser.h	2016-09-09 01:22:05 UTC (rev 205683)
+++ trunk/Source/WebCore/platform/URLParser.h	2016-09-09 01:32:18 UTC (rev 205684)
@@ -42,6 +42,7 @@
 private:
     URL m_url;
     StringBuilder m_buffer;
+    bool m_urlIsSpecial { false };
     void parseAuthority(StringView::CodePoints::Iterator&, const StringView::CodePoints::Iterator& end);
     bool parseHost(StringView::CodePoints::Iterator&, const StringView::CodePoints::Iterator& end);
     bool parsePort(StringView::CodePoints::Iterator&, const StringView::CodePoints::Iterator& end);

Modified: trunk/Tools/ChangeLog (205683 => 205684)


--- trunk/Tools/ChangeLog	2016-09-09 01:22:05 UTC (rev 205683)
+++ trunk/Tools/ChangeLog	2016-09-09 01:32:18 UTC (rev 205684)
@@ -1,3 +1,13 @@
+2016-09-08  Alex Christensen  <achristen...@webkit.org>
+
+        URLParser: Handle \ in paths of special URLs according to spec
+        https://bugs.webkit.org/show_bug.cgi?id=161781
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2016-09-08  Simon Fraser  <simon.fra...@apple.com>
 
         Update the content-animation.plan file to run css-accelerated-animation.html

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (205683 => 205684)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-09 01:22:05 UTC (rev 205683)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-09 01:32:18 UTC (rev 205684)
@@ -256,6 +256,7 @@
     checkRelativeURL("/path3", "http://u...@example.org/path1/path2", {"http", "user", "", "example.org", 0, "/path3", "", "", "http://u...@example.org/path3"});
     checkRelativeURL("", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar"});
     checkRelativeURL("  \a  \t\n", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar"});
+    checkRelativeURL(":foo.com\\", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/:foo.com/", "", "", "http://example.org/foo/:foo.com/"});
 }
 
 static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld)
@@ -398,6 +399,9 @@
     checkURLDifferences("http://[0:f::f:f:0:0]:65536",
         {"", "", "", "", 0, "", "", "", "http://[0:f::f:f:0:0]:65536"},
         {"http", "", "", "[0:f::f:f:0:0]", 65535, "/", "", "", "http://[0:f::f:f:0:0]:65536/"});
+    checkRelativeURLDifferences(":foo.com\\", "notspecial://example.org/foo/bar",
+        {"notspecial", "", "", "example.org", 0, "/foo/:foo.com\\", "", "", "notspecial://example.org/foo/:foo.com\\"},
+        {"notspecial", "", "", "example.org", 0, "/foo/:foo.com/", "", "", "notspecial://example.org/foo/:foo.com/"});
     
     // This behavior matches Chrome and Firefox, but not WebKit using URL::parse.
     // The behavior of URL::parse is clearly wrong because reparsing file://path would make path the host.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to