[BUGFIX] Convert URLs to punycode 51/56051/2
authorSybille Peters <sypets@gmx.de>
Wed, 21 Feb 2018 20:15:42 +0000 (21:15 +0100)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 8 Mar 2018 09:02:57 +0000 (10:02 +0100)
Resolves: #55155
Releases: master, 8.7
Change-Id: If7c099647a73d25f86ac38bdda67935deb4930e0
Reviewed-on: https://review.typo3.org/56051
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php
typo3/sysext/linkvalidator/Resources/Private/Language/Module/locallang.xlf

index 4709835..7f93fd4 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Linkvalidator\Linktype;
 
 use GuzzleHttp\Cookie\CookieJar;
 use GuzzleHttp\Exception\TooManyRedirectsException;
+use Mso\IdnaConvert\IdnaConvert;
 use TYPO3\CMS\Core\Http\RequestFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -65,15 +66,14 @@ class ExternalLinktype extends AbstractLinktype
             }
             return $this->urlReports[$url];
         }
-
         $options = [
             'cookies' => GeneralUtility::makeInstance(CookieJar::class),
             'allow_redirects' => ['strict' => true]
         ];
 
-        /** @var RequestFactory $requestFactory */
         $requestFactory = GeneralUtility::makeInstance(RequestFactory::class);
         try {
+            $url = $this->preprocessUrl($url);
             $response = $requestFactory->request($url, 'HEAD', $options);
             // HEAD was not allowed or threw an error, now trying GET
             if ($response->getStatusCode() >= 400) {
@@ -100,6 +100,7 @@ class ExternalLinktype extends AbstractLinktype
             $errorParams['errorType'] = 'network';
             $errorParams['message'] = $this->getErrorMessage($errorParams);
         } catch (\Exception $e) {
+            // Generic catch for anything else that may go wrong
             $isValidUrl = false;
             $errorParams['errorType'] = 'exception';
             $errorParams['message'] = $e->getMessage();
@@ -166,4 +167,15 @@ class ExternalLinktype extends AbstractLinktype
         }
         return $type;
     }
+
+    /**
+     * Convert given URL to punycode to handle domains with non-ASCII characters
+     *
+     * @param string $url
+     * @return string
+     */
+    protected function preprocessUrl(string $url): string
+    {
+        return (new IdnaConvert())->encode($url);
+    }
 }
index e9c7cbe..7df10c6 100644 (file)
                                <source>Exception: %s</source>
                        </trans-unit>
                        <trans-unit id="list.report.networkexception">
-                               <source>Network error</source>
+                               <source>Network error / invalid domain</source>
                        </trans-unit>
                        <trans-unit id="list.msg.ok">
                                <source>Ok</source>