URLParser should correctly strip unnecessary 0's in IPv6 addresses
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Oct 2016 18:27:53 +0000 (18:27 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Oct 2016 18:27:53 +0000 (18:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162979

Reviewed by Brady Eidson.

Source/WebCore:

Covered by new API tests.

* platform/URLParser.cpp:
(WebCore::URLParser::parseIPv6Host):
Strip leading 0's and any 0's before the last 0 if the value is 0.

Tools:

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

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

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

index 8a60c23..7302e8e 100644 (file)
@@ -1,5 +1,18 @@
 2016-10-05  Alex Christensen  <achristensen@webkit.org>
 
+        URLParser should correctly strip unnecessary 0's in IPv6 addresses
+        https://bugs.webkit.org/show_bug.cgi?id=162979
+
+        Reviewed by Brady Eidson.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::parseIPv6Host):
+        Strip leading 0's and any 0's before the last 0 if the value is 0.
+
+2016-10-05  Alex Christensen  <achristensen@webkit.org>
+
         UTF-8 encode queries of nonspecial and websocket schemes
         https://bugs.webkit.org/show_bug.cgi?id=162956
 
index 2e3c908..92ec581 100644 (file)
@@ -2361,6 +2361,7 @@ Optional<URLParser::IPv6Address> URLParser::parseIPv6Host(CodePointIterator<Char
         }
         uint16_t value = 0;
         size_t length = 0;
+        bool leadingZeros = false;
         for (; length < 4; length++) {
             if (c.atEnd())
                 break;
@@ -2368,10 +2369,13 @@ Optional<URLParser::IPv6Address> URLParser::parseIPv6Host(CodePointIterator<Char
                 break;
             if (isASCIIUpper(*c))
                 syntaxViolation(hostBegin);
+            if (*c == '0' && !length)
+                leadingZeros = true;
             value = value * 0x10 + toASCIIHexValue(*c);
             advance(c, hostBegin);
         }
-        if (UNLIKELY(length > 1 && !value))
+        
+        if (UNLIKELY((value && leadingZeros) || (!value && length > 1)))
             syntaxViolation(hostBegin);
 
         address[piecePointer++] = value;
index 0e95fa5..febfac6 100644 (file)
@@ -1,5 +1,15 @@
 2016-10-05  Alex Christensen  <achristensen@webkit.org>
 
+        URLParser should correctly strip unnecessary 0's in IPv6 addresses
+        https://bugs.webkit.org/show_bug.cgi?id=162979
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-10-05  Alex Christensen  <achristensen@webkit.org>
+
         UTF-8 encode queries of nonspecial and websocket schemes
         https://bugs.webkit.org/show_bug.cgi?id=162956
 
index a6bab9b..7a06242 100644 (file)
@@ -570,6 +570,21 @@ TEST_F(URLParserTest, ParserDifferences)
     checkURLDifferences("http://[a:0:0:0:b:c::d]",
         {"http", "", "", "[a::b:c:0:d]", 0, "/", "", "", "http://[a::b:c:0:d]/"},
         {"http", "", "", "[a:0:0:0:b:c::d]", 0, "/", "", "", "http://[a:0:0:0:b:c::d]/"});
+    checkURLDifferences("http://[::7f00:0001]/",
+        {"http", "", "", "[::7f00:1]", 0, "/", "", "", "http://[::7f00:1]/"},
+        {"http", "", "", "[::7f00:0001]", 0, "/", "", "", "http://[::7f00:0001]/"});
+    checkURLDifferences("http://[::7f00:00]/",
+        {"http", "", "", "[::7f00:0]", 0, "/", "", "", "http://[::7f00:0]/"},
+        {"http", "", "", "[::7f00:00]", 0, "/", "", "", "http://[::7f00:00]/"});
+    checkURLDifferences("http://[::0:7f00:0001]/",
+        {"http", "", "", "[::7f00:1]", 0, "/", "", "", "http://[::7f00:1]/"},
+        {"http", "", "", "[::0:7f00:0001]", 0, "/", "", "", "http://[::0:7f00:0001]/"});
+    checkURLDifferences("http://127.00.0.1/",
+        {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
+        {"http", "", "", "127.00.0.1", 0, "/", "", "", "http://127.00.0.1/"});
+    checkURLDifferences("http://127.0.0.01/",
+        {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
+        {"http", "", "", "127.0.0.01", 0, "/", "", "", "http://127.0.0.01/"});
     checkURLDifferences("http://example.com/path1/.%2e",
         {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"},
         {"http", "", "", "example.com", 0, "/path1/.%2e", "", "", "http://example.com/path1/.%2e"});