Title: [205824] trunk
Revision
205824
Author
achristen...@apple.com
Date
2016-09-12 14:30:30 -0700 (Mon, 12 Sep 2016)

Log Message

Remove trailing control characters and spaces before parsing a URL
https://bugs.webkit.org/show_bug.cgi?id=161870

Reviewed by Tim Horton.

Source/WebCore:

Covered by new API tests.

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

Tools:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (205823 => 205824)


--- trunk/Source/WebCore/ChangeLog	2016-09-12 21:23:12 UTC (rev 205823)
+++ trunk/Source/WebCore/ChangeLog	2016-09-12 21:30:30 UTC (rev 205824)
@@ -1,3 +1,16 @@
+2016-09-12  Alex Christensen  <achristen...@webkit.org>
+
+        Remove trailing control characters and spaces before parsing a URL
+        https://bugs.webkit.org/show_bug.cgi?id=161870
+
+        Reviewed by Tim Horton.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::bufferView):
+        (WebCore::URLParser::parse):
+
 2016-09-12  Chris Dumez  <cdu...@apple.com>
 
         window.performance object resets script-applied properties

Modified: trunk/Source/WebCore/platform/URLParser.cpp (205823 => 205824)


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-09-12 21:23:12 UTC (rev 205823)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-09-12 21:30:30 UTC (rev 205824)
@@ -241,12 +241,13 @@
     }
 }
 
-static StringView bufferView(const StringBuilder& builder, unsigned start, unsigned length)
+template<typename T>
+static StringView bufferView(const T& buffer, unsigned start, unsigned length)
 {
-    ASSERT(builder.length() >= length);
-    if (builder.is8Bit())
-        return StringView(builder.characters8() + start, length);
-    return StringView(builder.characters16() + start, length);
+    ASSERT(buffer.length() >= length);
+    if (buffer.is8Bit())
+        return StringView(buffer.characters8() + start, length);
+    return StringView(buffer.characters16() + start, length);
 }
 
 enum class URLParser::URLPart {
@@ -480,7 +481,10 @@
     // FIXME: We shouldn't need to allocate another buffer for this.
     StringBuilder queryBuffer;
 
-    auto codePoints = StringView(input).codePoints();
+    unsigned endIndex = input.length();
+    while (endIndex && isC0ControlOrSpace(input[endIndex - 1]))
+        endIndex--;
+    auto codePoints = bufferView(input, 0, endIndex).codePoints();
     auto c = codePoints.begin();
     auto end = codePoints.end();
     auto authorityOrHostBegin = codePoints.begin();

Modified: trunk/Tools/ChangeLog (205823 => 205824)


--- trunk/Tools/ChangeLog	2016-09-12 21:23:12 UTC (rev 205823)
+++ trunk/Tools/ChangeLog	2016-09-12 21:30:30 UTC (rev 205824)
@@ -1,5 +1,15 @@
 2016-09-12  Alex Christensen  <achristen...@webkit.org>
 
+        Remove trailing control characters and spaces before parsing a URL
+        https://bugs.webkit.org/show_bug.cgi?id=161870
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-09-12  Alex Christensen  <achristen...@webkit.org>
+
         Fix more URLParser quirks
         https://bugs.webkit.org/show_bug.cgi?id=161834
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (205823 => 205824)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-12 21:23:12 UTC (rev 205823)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-12 21:30:30 UTC (rev 205824)
@@ -202,6 +202,8 @@
     checkURL("sc:/pa", {"sc", "", "", "", 0, "/pa", "", "", "sc:/pa"});
     checkURL("sc:/pa/", {"sc", "", "", "", 0, "/pa/", "", "", "sc:/pa/"});
     checkURL("sc://pa/", {"sc", "", "", "pa", 0, "/", "", "", "sc://pa/"});
+    checkURL("http://host   \a   ", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
+    // FIXME: Fix and add a test with an invalid surrogate pair at the end with a space as the second code unit.
 
     // 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.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to