From 851d7ef4303d4d5e05c72a5d7c2cf529bee1d8ab Mon Sep 17 00:00:00 2001 From: Sybille Peters Date: Wed, 21 Feb 2018 21:15:42 +0100 Subject: [PATCH] [BUGFIX] Convert URLs to punycode Resolves: #55155 Releases: master, 8.7 Change-Id: If7c099647a73d25f86ac38bdda67935deb4930e0 Reviewed-on: https://review.typo3.org/55858 Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn Tested-by: TYPO3com Reviewed-by: Andreas Fernandez Tested-by: Andreas Fernandez --- .../Classes/Linktype/ExternalLinktype.php | 16 ++++++++++++++-- .../Private/Language/Module/locallang.xlf | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php b/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php index 47098351ca81..7f93fd435e4b 100644 --- a/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php +++ b/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php @@ -16,6 +16,7 @@ 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 @@ public function checkLink($url, $softRefEntry, $reference) } 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 @@ public function checkLink($url, $softRefEntry, $reference) $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 @@ public function fetchType($value, $type, $key) } 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); + } } diff --git a/typo3/sysext/linkvalidator/Resources/Private/Language/Module/locallang.xlf b/typo3/sysext/linkvalidator/Resources/Private/Language/Module/locallang.xlf index e9c7cbe29ee3..7df10c602f57 100644 --- a/typo3/sysext/linkvalidator/Resources/Private/Language/Module/locallang.xlf +++ b/typo3/sysext/linkvalidator/Resources/Private/Language/Module/locallang.xlf @@ -184,7 +184,7 @@ Exception: %s - Network error + Network error / invalid domain Ok