Skip to content

Commit 791fe2f

Browse files
committed
fix: auto_link() converts invalid string like "://codeigniter.com"
The scheme is missing, so it is not a valid URL.
1 parent 0a6b39d commit 791fe2f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

system/Helpers/url_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function safe_mailto(string $email, string $title = '', $attributes = ''): strin
351351
function auto_link(string $str, string $type = 'both', bool $popup = false): string
352352
{
353353
// Find and replace any URLs.
354-
if ($type !== 'email' && preg_match_all('#(\w*://|www\.)[a-z0-9]+(-+[a-z0-9]+)*(\.[a-z0-9]+(-+[a-z0-9]+)*)+(/([^\s()<>;]+\w)?/?)?#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
354+
if ($type !== 'email' && preg_match_all('#([a-z][a-z0-9+\-.]*://|www\.)[a-z0-9]+(-+[a-z0-9]+)*(\.[a-z0-9]+(-+[a-z0-9]+)*)+(/([^\s()<>;]+\w)?/?)?#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
355355
// Set our target HTML if using popup links.
356356
$target = ($popup) ? ' target="_blank"' : '';
357357

tests/system/Helpers/URLHelper/MiscUrlTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public static function provideAutoLinkUrl(): iterable
523523
],
524524
'test06' => [
525525
'This one: ://codeigniter.com must not break this one: http://codeigniter.com',
526-
'This one: <a href="://codeigniter.com">://codeigniter.com</a> must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>',
526+
'This one: ://codeigniter.com must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>',
527527
],
528528
'test07' => [
529529
'Visit example.com or email [email protected]',
@@ -623,7 +623,7 @@ public static function provideAutolinkBoth(): iterable
623623
],
624624
'test06' => [
625625
'This one: ://codeigniter.com must not break this one: http://codeigniter.com',
626-
'This one: <a href="://codeigniter.com">://codeigniter.com</a> must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>',
626+
'This one: ://codeigniter.com must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>',
627627
],
628628
'test07' => [
629629
'Visit example.com or email [email protected]',
@@ -675,7 +675,7 @@ public static function provideAutoLinkPopup(): iterable
675675
],
676676
'test06' => [
677677
'This one: ://codeigniter.com must not break this one: http://codeigniter.com',
678-
'This one: <a href="://codeigniter.com" target="_blank">://codeigniter.com</a> must not break this one: <a href="http://codeigniter.com" target="_blank">http://codeigniter.com</a>',
678+
'This one: ://codeigniter.com must not break this one: <a href="http://codeigniter.com" target="_blank">http://codeigniter.com</a>',
679679
],
680680
'test07' => [
681681
'Visit example.com or email [email protected]',

0 commit comments

Comments
 (0)