diff -u b/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php --- b/core/lib/Drupal/Component/Utility/UrlHelper.php +++ b/core/lib/Drupal/Component/Utility/UrlHelper.php @@ -4,7 +4,6 @@ use Symfony\Component\Validator\Constraints\Url; use Symfony\Component\Validator\Constraints\NotBlank; -use Symfony\Component\Validator\Constraints\NotBlankValidator; use Symfony\Component\Validator\Validation; /** @@ -398,8 +397,9 @@ */ public static function isValid($url, $absolute = FALSE) { if ($absolute) { + $allowed_protocols = array_unique(array_merge(static::$allowedProtocols, ['http', 'https', 'ftp', 'feed'])); $violations = Validation::createValidator()->validate($url, [ - new Url(['protocols' => ['http', 'https', 'ftp', 'feed']]), + new Url(['protocols' => $allowed_protocols]), new NotBlank(), ]); return !(bool) count($violations); diff -u b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php --- b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -75,33 +75,7 @@ // @see https://uasg.tech/ 'ua-test.link', 'ua-test.technology', - // cSpell:disable - '普遍接受-测试.top', - 'ua-test.世界', - '普遍接受-测试.世界', - '普遍接受-测试.世界', - // cSpell:enable - // @todo Open dot domains do not validate correctly - they should. - // cSpell:disable - // '普遍接受-测试。世界', - 'ua-test.xn--rhqv96g', - 'xn----f38am99bqvcd5liy1cxsg.top', - 'xn----f38am99bqvcd5liy1cxsg.xn--rhqv96g', - 'اختبار-القبولالعالمي.top', - 'اختبار-القبولالعالمي.شبكة', - 'ua-test.link/我的页面', - 'ua-test.technology/我的页面', - '普遍接受-测试.top/我的页面', - 'ua-test.世界/我的页面', - '普遍接受-测试.世界/我的页面', - // cSpell:enable - // @todo Open dot domains do not validate correctly - they should. - // '普遍接受-测试。世界/我的页面', - // cSpell:disable - 'ختبار-القبولالعالمي.top/我的页面', - 'اختبار-القبولالعالمي.شبكة/我的页面', - // cSpell:enable - 'www.example.com/', + 'www.example.com/', // Strings within parenthesis without leading space char. 'www.example.com/strings_(string_within_parenthesis)', // Numbers within parenthesis without leading space char. @@ -116,10 +90,6 @@ "foo.com/blah_blah/", "foo.com/blah_blah_(wikipedia)", "foo.com/blah_blah_(wikipedia)_(again)", - // cSpell: disable - "www.example.com/wpstyle/?p=364", - "www.example.com/foo/?bar=baz&inga=42&quux", - // cSpell: enable "✪df.ws/123", "userid:password@example.com:8080", "userid:password@example.com:8080/", @@ -137,21 +107,39 @@ // @todo this Url should validation. // "foo.com/unicode_(✪)_in_parens", "foo.com/(something)?after=parens", - // cSpell: disable - "☺.damowmow.com/", - // cSpell: enable "code.google.com/events/#&product=browser", "j.mp", "foo.bar/baz", "foo.bar/?q=Test%20URL-encoded%20stuff", - // cSpell: disable - "مثال.إختبار", - "例子.测试", - // cSpell: enable // @todo this Url should validation. // "-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", "1337.net", "a.b-c.de", + // cSpell: disable + '普遍接受-测试.top', + 'ua-test.世界', + '普遍接受-测试.世界', + // @todo Open dot domains do not validate correctly - they should. + // '普遍接受-测试。世界', + // '普遍接受-测试。世界/我的页面', + 'ua-test.xn--rhqv96g', + 'xn----f38am99bqvcd5liy1cxsg.top', + 'xn----f38am99bqvcd5liy1cxsg.xn--rhqv96g', + 'اختبار-القبولالعالمي.top', + 'اختبار-القبولالعالمي.شبكة', + 'ua-test.link/我的页面', + 'ua-test.technology/我的页面', + '普遍接受-测试.top/我的页面', + 'ua-test.世界/我的页面', + '普遍接受-测试.世界/我的页面', + 'ختبار-القبولالعالمي.top/我的页面', + 'اختبار-القبولالعالمي.شبكة/我的页面', + "www.example.com/wpstyle/?p=364", + "www.example.com/foo/?bar=baz&inga=42&quux", + "☺.damowmow.com/", + "مثال.إختبار", + "例子.测试", + // cSpell: enable ]; return $this->dataEnhanceWithScheme($urls); @@ -214,16 +202,16 @@ // '.www.foo.bar./', ]; $schemes = [ + ['', ''], + ['foo.bar/', 'ftps'], + ['foo.com', ''], + ['not-a-valid-scheme', 'invalid'], + ['test', ''], + ['test', 'h'], // cSpell: disable [' shouldfail', '://'], ['1234', 'rdar'], // cSpell: enable - ['not-a-valid-scheme', 'invalid'], - ['test', 'h'], - ['foo.bar/', 'ftps'], - ['foo.com', ''], - ['test', ''], - ['', ''], ]; return array_merge($schemes, $this->dataEnhanceWithScheme($data)); }