From 3d310cf0bff18d327fa60e60463964a5857bea39 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Sep 2024 16:40:00 +0900 Subject: [PATCH 1/3] test: add tests for auto_link() --- tests/system/Helpers/URLHelper/MiscUrlTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/system/Helpers/URLHelper/MiscUrlTest.php b/tests/system/Helpers/URLHelper/MiscUrlTest.php index 125356e7d0ed..219b5322dbb5 100644 --- a/tests/system/Helpers/URLHelper/MiscUrlTest.php +++ b/tests/system/Helpers/URLHelper/MiscUrlTest.php @@ -533,6 +533,10 @@ public static function provideAutoLinkUrl(): iterable 'Visit www.example.com or email foo@bar.com', 'Visit www.example.com or email foo@bar.com', ], + 'trailing slash' => [ + 'Trailing slash: https://codeigniter.com/ fubar', + 'Trailing slash: https://codeigniter.com/ fubar', + ], ]; } @@ -629,6 +633,10 @@ public static function provideAutolinkBoth(): iterable 'Visit www.example.com or email foo@bar.com', "Visit www.example.com or email ", ], + 'email starting with "www."' => [ + 'this is some text that includes www.email@domain.com which is causing an issue', + 'this is some text that includes ' . safe_mailto('www.email@domain.com') . ' which is causing an issue', + ], ]; } From d7da0b8cef90a11a61dd62f248042f445bbc3b38 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 5 Sep 2024 16:40:33 +0900 Subject: [PATCH 2/3] fix: auto_link() regexp From CI3. See https://github.com/bcit-ci/CodeIgniter/blob/2042929bab8ffc14faf6193de0107b7f95abbdaf/system/helpers/url_helper.php#L397 --- system/Helpers/url_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 1d03132d82cf..d68fea2aad7d 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -351,7 +351,7 @@ function safe_mailto(string $email, string $title = '', $attributes = ''): strin function auto_link(string $str, string $type = 'both', bool $popup = false): string { // Find and replace any URLs. - if ($type !== 'email' && preg_match_all('#(\w*://|www\.)[^\s()<>;]+\w#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { + 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)) { // Set our target HTML if using popup links. $target = ($popup) ? ' target="_blank"' : ''; From fdba50299c35fe29a2a25a7521b009a8f094b17f Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 6 Sep 2024 10:33:06 +0900 Subject: [PATCH 3/3] docs: add changelog --- user_guide_src/source/changelogs/v4.5.5.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_guide_src/source/changelogs/v4.5.5.rst b/user_guide_src/source/changelogs/v4.5.5.rst index f6799e484ebf..aaea324399af 100644 --- a/user_guide_src/source/changelogs/v4.5.5.rst +++ b/user_guide_src/source/changelogs/v4.5.5.rst @@ -30,6 +30,10 @@ Deprecations Bugs Fixed ********** +- **URL Helper:** The bug where the regular expression in :php:func:`auto_link()` + was old has been fixed. As a result of this fix, the same regular expression as + CodeIgniter 3 is now used. + See the repo's `CHANGELOG.md `_ for a complete list of bugs fixed.