URLParser should convert ASCII hosts to lowercase
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2016 23:39:11 +0000 (23:39 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2016 23:39:11 +0000 (23:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161820

Reviewed by Geoffrey Garen.

Source/WebCore:

Covered by new API tests.

* platform/URLParser.cpp:
(WebCore::domainToASCII):
The fast path for domains that are already ASCII and do not need punycode encoding
should convert the domain to lowercase.
This matches behavior in URL::parse if isCanonicalHostnameLowercaseForScheme is true,
and RFC 5890.

Tools:

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

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

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

index 0cf469b..5091dde 100644 (file)
@@ -1,3 +1,19 @@
+2016-09-09  Alex Christensen  <achristensen@webkit.org>
+
+        URLParser should convert ASCII hosts to lowercase
+        https://bugs.webkit.org/show_bug.cgi?id=161820
+
+        Reviewed by Geoffrey Garen.
+
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::domainToASCII):
+        The fast path for domains that are already ASCII and do not need punycode encoding
+        should convert the domain to lowercase.
+        This matches behavior in URL::parse if isCanonicalHostnameLowercaseForScheme is true,
+        and RFC 5890.
+
 2016-09-09  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Remove unused member of GlyphBuffer
index 6204526..d942d0c 100644 (file)
@@ -1334,12 +1334,12 @@ static Optional<String> domainToASCII(const String& domain)
 
     if (containsOnlyASCII(domain)) {
         if (domain.is8Bit())
-            return domain;
+            return domain.convertToASCIILowercase();
         Vector<LChar, hostnameBufferLength> buffer;
         size_t length = domain.length();
         buffer.reserveInitialCapacity(length);
         for (size_t i = 0; i < length; ++i)
-            buffer.append(domain[i]);
+            buffer.append(toASCIILower(domain[i]));
         return String(buffer.data(), length);
     }
     
index 5570e1d..04a6fcb 100644 (file)
@@ -1,3 +1,13 @@
+2016-09-09  Alex Christensen  <achristensen@webkit.org>
+
+        URLParser should convert ASCII hosts to lowercase
+        https://bugs.webkit.org/show_bug.cgi?id=161820
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2016-09-09  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r205759.
index 8df5177..a8c5909 100644 (file)
@@ -164,7 +164,10 @@ TEST_F(URLParserTest, Basic)
     checkURL("file://localhost/path", {"file", "", "", "", 0, "/path", "", "", "file:///path"});
     checkURL("file://localhost/", {"file", "", "", "", 0, "/", "", "", "file:///"});
     checkURL("file://localhost", {"file", "", "", "", 0, "/", "", "", "file:///"});
-    // FIXME: check file://lOcAlHoSt etc.
+    checkURL("file://lOcAlHoSt", {"file", "", "", "", 0, "/", "", "", "file:///"});
+    checkURL("file://lOcAlHoSt/", {"file", "", "", "", 0, "/", "", "", "file:///"});
+    checkURL("file:/pAtH/", {"file", "", "", "", 0, "/pAtH/", "", "", "file:///pAtH/"});
+    checkURL("file:/pAtH", {"file", "", "", "", 0, "/pAtH", "", "", "file:///pAtH"});
     checkURL("file:?query", {"file", "", "", "", 0, "/", "query", "", "file:///?query"});
     checkURL("file:#fragment", {"file", "", "", "", 0, "/", "", "fragment", "file:///#fragment"});
     checkURL("file:?query#fragment", {"file", "", "", "", 0, "/", "query", "fragment", "file:///?query#fragment"});
@@ -268,6 +271,7 @@ TEST_F(URLParserTest, ParseRelative)
     checkRelativeURL("http:\\\\foo.com\\", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "/", "", "", "http://foo.com/"});
     checkRelativeURL("http:\\\\foo.com/", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "/", "", "", "http://foo.com/"});
     checkRelativeURL("http:\\\\foo.com", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "/", "", "", "http://foo.com/"});
+    checkRelativeURL("http://ExAmPlE.CoM", "http://other.com", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
 }
 
 static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld)
@@ -438,6 +442,12 @@ TEST_F(URLParserTest, ParserDifferences)
     checkURLDifferences("file:path",
         {"file", "", "", "", 0, "/path", "", "", "file:///path"},
         {"file", "", "", "", 0, "path", "", "", "file://path"});
+    checkURLDifferences("file:pAtH",
+        {"file", "", "", "", 0, "/pAtH", "", "", "file:///pAtH"},
+        {"file", "", "", "", 0, "pAtH", "", "", "file://pAtH"});
+    checkURLDifferences("file:pAtH/",
+        {"file", "", "", "", 0, "/pAtH/", "", "", "file:///pAtH"},
+        {"file", "", "", "", 0, "pAtH/", "", "", "file://pAtH"});
     
     // FIXME: Fix and test incomplete percent encoded characters in the middle and end of the input string.
     // FIXME: Fix and test percent encoded upper case characters in the host.