Allow UIDNAInfo.errors from uidna_nameToUnicode that would not cause URL parsing...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Feb 2020 19:09:32 +0000 (19:09 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Feb 2020 19:09:32 +0000 (19:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207360
<rdar://problem/57825317>

Patch by Alex Christensen <achristensen@webkit.org> on 2020-02-14
Reviewed by Ryosuke Niwa.

Source/WTF:

* wtf/URLHelpers.cpp:
(WTF::URLHelpers::mapHostName):

Tools:

* TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
(TestWebKitAPI::TEST):

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

Source/WTF/ChangeLog
Source/WTF/wtf/URLHelpers.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm

index 2c91c30..e848368 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-14  Alex Christensen  <achristensen@webkit.org>
+
+        Allow UIDNAInfo.errors from uidna_nameToUnicode that would not cause URL parsing failures
+        https://bugs.webkit.org/show_bug.cgi?id=207360
+        <rdar://problem/57825317>
+
+        Reviewed by Ryosuke Niwa.
+
+        * wtf/URLHelpers.cpp:
+        (WTF::URLHelpers::mapHostName):
+
 2020-02-12  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         WebP image format is not supported
index c584f1a..5e0ff10 100644 (file)
@@ -548,7 +548,8 @@ Optional<String> mapHostName(const String& hostName, const Optional<URLDecodeFun
     UErrorCode uerror = U_ZERO_ERROR;
     UIDNAInfo processingDetails = UIDNA_INFO_INITIALIZER;
     int32_t numCharactersConverted = (decodeFunction ? uidna_nameToASCII : uidna_nameToUnicode)(&URLParser::internationalDomainNameTranscoder(), sourceBuffer.data(), length, destinationBuffer, hostNameBufferLength, &processingDetails, &uerror);
-    if (length && (U_FAILURE(uerror) || processingDetails.errors))
+    int allowedErrors = decodeFunction ? 0 : UIDNA_ERROR_EMPTY_LABEL | UIDNA_ERROR_LEADING_HYPHEN | UIDNA_ERROR_TRAILING_HYPHEN | UIDNA_ERROR_HYPHEN_3_4;
+    if (length && (U_FAILURE(uerror) || processingDetails.errors & ~allowedErrors))
         return nullopt;
     
     if (numCharactersConverted == static_cast<int32_t>(length) && !memcmp(sourceBuffer.data(), destinationBuffer, length * sizeof(UChar)))
index 453d404..61dc1e9 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-14  Alex Christensen  <achristensen@webkit.org>
+
+        Allow UIDNAInfo.errors from uidna_nameToUnicode that would not cause URL parsing failures
+        https://bugs.webkit.org/show_bug.cgi?id=207360
+        <rdar://problem/57825317>
+
+        Reviewed by Ryosuke Niwa.
+
+        * TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
+        (TestWebKitAPI::TEST):
+
 2020-02-14  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake] Add Fontconfig::Fontconfig target
index 41faeb7..c81882b 100644 (file)
@@ -70,6 +70,13 @@ TEST(WTF_URLExtras, URLExtras)
 
     EXPECT_STREQ("http://site.com", userVisibleString(literalURL("http://site.com")));
     EXPECT_STREQ("http://%77ebsite.com", userVisibleString(literalURL("http://%77ebsite.com")));
+
+    EXPECT_STREQ("-.example.com", [WTF::decodeHostName(@"-.example.com") UTF8String]);
+    EXPECT_STREQ("-a.example.com", [WTF::decodeHostName(@"-a.example.com") UTF8String]);
+    EXPECT_STREQ("a-.example.com", [WTF::decodeHostName(@"a-.example.com") UTF8String]);
+    EXPECT_STREQ("ab--cd.example.com", [WTF::decodeHostName(@"ab--cd.example.com") UTF8String]);
+    EXPECT_STREQ(".example.com", [WTF::decodeHostName(@"xn--.example.com") UTF8String]);
+    EXPECT_STREQ("a..example.com", [WTF::decodeHostName(@"a..example.com") UTF8String]);
 }
     
 TEST(WTF_URLExtras, URLExtras_Spoof)