-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: auto_link() fails to include trailing slashes in URLs #9165
Comments
#158 The first commit of The regex is not changed from the beginning. preg_match_all('#(\w*://|www\.)[^\s()<>;]+\w#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER) But the regex in CI3 is the following: 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) It seems it was changed in bcit-ci/CodeIgniter@8c9e510. |
Thanks for looking into this. I messed up with my PR, apologies. |
No problem. It is almost impossible for anyone to send a perfect PR at first. I sent #9169. Please check. |
@codeigniter4/core-team The link
CodeIgniter4/tests/system/Helpers/URLHelper/MiscUrlTest.php Lines 525 to 526 in ffd1b68
|
I guess that |
Yes, |
The range of what will "catch" on this rule is large, but thanks to this we have support for all direct links that are supported by many apps, like |
Telegram API https://core.telegram.org/api/links |
Okay, the current behavior seems useful, and can catch unknown schemes. |
RFC 3986 states that the scheme component is required.
I would think that it should catch |
|
Yes. |
I sent #9180 |
PHP Version
8.2
CodeIgniter4 Version
4.5.4
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
Using the URL Helper
auto_link()
function to automatically turn URLs contained in a string into links/HTML anchor elements. If the last character of the URL is a /, it is not included in either the anchor href value or text value.Steps to Reproduce
Input:
Output:
Expected Output
Anything else?
I came across this as it seems that the default behaviour of Chrome and Firefox is to include the trailing slash when copying the URL from the browser's address bar. I tend to do this a lot and noticed that the
auto_link()
function always missed the trailing slash when creating anchor elements.The text was updated successfully, but these errors were encountered: