Skip to content

Commit

Permalink
[BUGFIX] Convert URLs to punycode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sypets authored and andreaskienast committed Mar 8, 2018
1 parent 1f4cb28 commit f9d07db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Up @@ -184,7 +184,7 @@
<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>
Expand Down

0 comments on commit f9d07db

Please sign in to comment.