diff --git a/app/bundles/CoreBundle/Helper/UrlHelper.php b/app/bundles/CoreBundle/Helper/UrlHelper.php index 4a13fff0460..84a3d835ca6 100644 --- a/app/bundles/CoreBundle/Helper/UrlHelper.php +++ b/app/bundles/CoreBundle/Helper/UrlHelper.php @@ -286,18 +286,19 @@ private static function removeTrailingNonAlphaNumeric($string) } /** - * FILTER_VALIDATE_URL allow only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed]. This validation passed also special characters in URL. + * This method return true with special characters in URL, for example https://domain.tld/é.pdf + * filter_var($url, FILTER_VALIDATE_URL) allow only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed]. * * @param string $url * * @return bool */ - public static function isValidateUrl($url) + public static function isValidUrl($url) { $path = parse_url($url, PHP_URL_PATH); $encodedPath = array_map('urlencode', explode('/', $path)); $url = str_replace($path, implode('/', $encodedPath), $url); - return filter_var($url, FILTER_VALIDATE_URL); + return (bool) filter_var($url, FILTER_VALIDATE_URL); } } diff --git a/app/bundles/CoreBundle/Tests/unit/Helper/UrlHelperTest.php b/app/bundles/CoreBundle/Tests/unit/Helper/UrlHelperTest.php index fba8cdcec6e..90c5de34786 100644 --- a/app/bundles/CoreBundle/Tests/unit/Helper/UrlHelperTest.php +++ b/app/bundles/CoreBundle/Tests/unit/Helper/UrlHelperTest.php @@ -149,4 +149,12 @@ public function testGetUrlsFromPlaintextWithSymbols() ) ); } + + public function testUrlValid() + { + $this->assertTrue(UrlHelper::isValidUrl('https://domain.tld/e')); + $this->assertTrue(UrlHelper::isValidUrl('https://domain.tld/é')); + $this->assertFalse(UrlHelper::isValidUrl('notvalidurl')); + $this->assertFalse(UrlHelper::isValidUrl('notvalidurlé')); + } } diff --git a/app/bundles/PageBundle/Controller/PublicController.php b/app/bundles/PageBundle/Controller/PublicController.php index af0535c35d7..7c7bc4b48d4 100644 --- a/app/bundles/PageBundle/Controller/PublicController.php +++ b/app/bundles/PageBundle/Controller/PublicController.php @@ -480,7 +480,7 @@ public function redirectAction($redirectId) $url = UrlHelper::sanitizeAbsoluteUrl($url); - if (!UrlHelper::isValidateUrl($url)) { + if (!UrlHelper::isValidUrl($url)) { throw $this->createNotFoundException($this->translator->trans('mautic.core.url.error.404', ['%url%' => $url])); }