Title: [206614] trunk
Revision
206614
Author
[email protected]
Date
2016-09-29 14:20:43 -0700 (Thu, 29 Sep 2016)

Log Message

URLParser should correctly parse ports with leading 0's
https://bugs.webkit.org/show_bug.cgi?id=162752

Reviewed by Tim Horton.

Source/WebCore:

Covered by new API tests.

* platform/URLParser.cpp:
(WebCore::URLParser::parsePort):

Tools:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206613 => 206614)


--- trunk/Source/WebCore/ChangeLog	2016-09-29 21:13:33 UTC (rev 206613)
+++ trunk/Source/WebCore/ChangeLog	2016-09-29 21:20:43 UTC (rev 206614)
@@ -1,3 +1,15 @@
+2016-09-29  Alex Christensen  <[email protected]>
+
+        URLParser should correctly parse ports with leading 0's
+        https://bugs.webkit.org/show_bug.cgi?id=162752
+
+        Reviewed by Tim Horton.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::parsePort):
+
 2016-09-29  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r206483.

Modified: trunk/Source/WebCore/platform/URLParser.cpp (206613 => 206614)


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-09-29 21:13:33 UTC (rev 206613)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-09-29 21:20:43 UTC (rev 206614)
@@ -2361,6 +2361,9 @@
         syntaxViolation(colonIterator);
         return true;
     }
+    bool seenDigit = false;
+    bool seenMultipleDigits = false;
+    bool leadingZeros = false;
     for (; !iterator.atEnd(); ++iterator) {
         if (UNLIKELY(isTabOrNewline(*iterator))) {
             syntaxViolation(colonIterator);
@@ -2367,6 +2370,11 @@
             continue;
         }
         if (isASCIIDigit(*iterator)) {
+            if (*iterator == '0' && !seenDigit)
+                leadingZeros = true;
+            if (seenDigit)
+                seenMultipleDigits = true;
+            seenDigit = true;
             port = port * 10 + *iterator - '0';
             if (port > std::numeric_limits<uint16_t>::max())
                 return false;
@@ -2374,6 +2382,12 @@
             return false;
     }
 
+    if (port && leadingZeros)
+        syntaxViolation(colonIterator);
+    
+    if (!port && seenMultipleDigits)
+        syntaxViolation(colonIterator);
+
     if (UNLIKELY(isDefaultPort(parsedDataView(0, m_url.m_schemeEnd), port)))
         syntaxViolation(colonIterator);
     else {

Modified: trunk/Tools/ChangeLog (206613 => 206614)


--- trunk/Tools/ChangeLog	2016-09-29 21:13:33 UTC (rev 206613)
+++ trunk/Tools/ChangeLog	2016-09-29 21:20:43 UTC (rev 206614)
@@ -1,5 +1,15 @@
 2016-09-29  Alex Christensen  <[email protected]>
 
+        URLParser should correctly parse ports with leading 0's
+        https://bugs.webkit.org/show_bug.cgi?id=162752
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-09-29  Alex Christensen  <[email protected]>
+
         URLParser: make parsing invalid IPv4 addresses more robust and correct
         https://bugs.webkit.org/show_bug.cgi?id=162746
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (206613 => 206614)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-29 21:13:33 UTC (rev 206613)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-29 21:20:43 UTC (rev 206614)
@@ -396,6 +396,7 @@
     checkRelativeURL("://:0/", "http://webkit.org/", {"http", "", "", "webkit.org", 0, "/://:0/", "", "", "http://webkit.org/://:0/"});
     checkRelativeURL(String(), "http://webkit.org/", {"http", "", "", "webkit.org", 0, "/", "", "", "http://webkit.org/"});
     checkRelativeURL("https://@test@test@example:800\\path@end", "http://doesnotmatter/", {"", "", "", "", 0, "", "", "", "https://@test@test@example:800\\path@end"});
+    checkRelativeURL("http://f:0/c", "http://example.org/foo/bar", {"http", "", "", "f", 0, "/c", "", "", "http://f:0/c"});
 
     // 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.
@@ -766,6 +767,12 @@
     checkURLDifferences("http://127.0.1.~",
         {"http", "", "", "127.0.1.~", 0, "/", "", "", "http://127.0.1.~/"},
         {"", "", "", "", 0, "", "", "", "http://127.0.1.~"});
+    checkRelativeURLDifferences("http://f:000/c", "http://example.org/foo/bar",
+        {"http", "", "", "f", 0, "/c", "", "", "http://f:0/c"},
+        {"http", "", "", "f", 0, "/c", "", "", "http://f:000/c"});
+    checkRelativeURLDifferences("http://f:010/c", "http://example.org/foo/bar",
+        {"http", "", "", "f", 10, "/c", "", "", "http://f:10/c"},
+        {"http", "", "", "f", 10, "/c", "", "", "http://f:010/c"});
 }
 
 TEST_F(URLParserTest, DefaultPort)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to