Skip to content

Commit aecedbc

Browse files
committed
Support non-http/https URL schemes
Fixes #14830
1 parent 6d94861 commit aecedbc

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Fixed a bug where the Database Backup utility was present when the `backupCommand` config setting was set to `false`.
77
- Fixed an error that occurred when running the `db/convert-charset` command, if any tables contained `char` or `varchar` foreign key columns. ([#14815](https://github.com/craftcms/cms/issues/14815))
88
- Fixed a bug where parsed first/last names could have different casing than the full name that was submitted. ([#14723](https://github.com/craftcms/cms/issues/14723))
9+
- Fixed a bug where `craft\helpers\UrlHelper::isAbsoluteUrl()` was returning `false` for URLs with schemes other than `http` or `https`, such as `mailto` and `tel`. ([#14830](https://github.com/craftcms/cms/issues/14830))
910

1011
## 4.8.9 - 2024-04-10
1112

src/helpers/UrlHelper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ class UrlHelper
2727
*/
2828
public static function isAbsoluteUrl(string $url): bool
2929
{
30-
return (str_starts_with($url, 'http://') || str_starts_with($url, 'https://'));
30+
// From https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler:
31+
// > Scheme names are case sensitive, must start with an ASCII letter, and may contain only ASCII letters,
32+
// > numbers, the “+” character, the “-” character, and the “.” character.
33+
return (bool)preg_match('/^[a-z][a-z0-9+-.]*:/i', $url);
3134
}
3235

3336
/**

tests/unit/helpers/UrlHelperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class UrlHelperTest extends TestCase
3131
public const NON_ABSOLUTE_URL = 'craftcms.com/';
3232
public const NON_ABSOLUTE_URL_WWW = 'www.craftcms.com/';
3333
public const PROTOCOL_RELATIVE_URL = '//craftcms.com/';
34+
public const EMAIL_URL = 'mailto:[email protected]';
35+
public const TEL_URL = 'tel:+10123456789';
3436

3537
/**
3638
* @var UnitTester
@@ -303,6 +305,8 @@ public function isAbsoluteUrlDataProvider(): array
303305
'absolute-url-www' => [true, self::ABSOLUTE_URL_WWW],
304306
'non-url' => [false, self::NON_ABSOLUTE_URL],
305307
'non-absolute-url-www' => [false, self::NON_ABSOLUTE_URL_WWW],
308+
'email-url' => [true, self::EMAIL_URL],
309+
'tel-url' => [true, self::TEL_URL],
306310
];
307311
}
308312

0 commit comments

Comments
 (0)