From ee8d783d050588aaf35261b7d1832e2bdc433fe6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 20 Apr 2024 15:42:42 +0100 Subject: [PATCH] better support for external urls in Utils::url() --- CHANGELOG.md | 2 ++ system/src/Grav/Common/Uri.php | 2 +- tests/unit/Grav/Common/UtilsTest.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7758825c4e..966b2f2edc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v1.7.46 ## mm/dd/2024 +1. [](#improved) + * Better handling of external protocols in `Utils::url()` such as `mailto:`, `tel:`, etc. 1. [](#bugfix) * Fixes for multi-lang taxonomy when reinitializing the languages (e.g. LangSwitcher plugin) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 9d3ef5bb94..374dccce27 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -742,7 +742,7 @@ public static function getCurrentRoute() */ public static function isExternal($url) { - return (0 === strpos($url, 'http://') || 0 === strpos($url, 'https://') || 0 === strpos($url, '//')); + return (0 === strpos($url, 'http://') || 0 === strpos($url, 'https://') || 0 === strpos($url, '//') || 0 === strpos($url, 'mailto:') || 0 === strpos($url, 'tel:') || 0 === strpos($url, 'ftp://') || 0 === strpos($url, 'ftps://') || 0 === strpos($url, 'news:') || 0 === strpos($url, 'irc:') || 0 === strpos($url, 'gopher:') || 0 === strpos($url, 'nntp:') || 0 === strpos($url, 'feed:') || 0 === strpos($url, 'cvs:') || 0 === strpos($url, 'ssh:') || 0 === strpos($url, 'git:') || 0 === strpos($url, 'svn:') || 0 === strpos($url, 'hg:')); } /** diff --git a/tests/unit/Grav/Common/UtilsTest.php b/tests/unit/Grav/Common/UtilsTest.php index 0e530497cb..9a29ad7e2f 100644 --- a/tests/unit/Grav/Common/UtilsTest.php +++ b/tests/unit/Grav/Common/UtilsTest.php @@ -461,7 +461,7 @@ public function testUrl(): void self::assertSame('pop://domain.com', Utils::url('pop://domain.com')); self::assertSame('foo://bar/baz', Utils::url('foo://bar/baz')); self::assertSame('foo://bar/baz', Utils::url('foo://bar/baz', true)); - // self::assertSame('mailto:joe@domain.com', Utils::url('mailto:joe@domain.com', true)); // FIXME <- + self::assertSame('mailto:joe@domain.com', Utils::url('mailto:joe@domain.com', true)); // FIXME <- } public function testUrlWithRoot(): void