URLParser should correctly parse ports with leading 0's
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Sep 2016 21:20:43 +0000 (21:20 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Sep 2016 21:20:43 +0000 (21:20 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206614 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/URLParser.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

index fd09a82..8bee0db 100644 (file)
@@ -1,3 +1,15 @@
+2016-09-29  Alex Christensen  <achristensen@webkit.org>
+
+        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  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r206483.
index accbd89..99a3c14 100644 (file)
@@ -2361,12 +2361,20 @@ bool URLParser::parsePort(CodePointIterator<CharacterType>& iterator)
         syntaxViolation(colonIterator);
         return true;
     }
+    bool seenDigit = false;
+    bool seenMultipleDigits = false;
+    bool leadingZeros = false;
     for (; !iterator.atEnd(); ++iterator) {
         if (UNLIKELY(isTabOrNewline(*iterator))) {
             syntaxViolation(colonIterator);
             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 @@ bool URLParser::parsePort(CodePointIterator<CharacterType>& iterator)
             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 {
index 20ca6a4..2c55da5 100644 (file)
@@ -1,5 +1,15 @@
 2016-09-29  Alex Christensen  <achristensen@webkit.org>
 
+        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  <achristensen@webkit.org>
+
         URLParser: make parsing invalid IPv4 addresses more robust and correct
         https://bugs.webkit.org/show_bug.cgi?id=162746
 
index 5d2e5a4..e6ccdfe 100644 (file)
@@ -396,6 +396,7 @@ TEST_F(URLParserTest, ParseRelative)
     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 @@ TEST_F(URLParserTest, ParserDifferences)
     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)