Skip to content

Bug: auto_link() fails to include trailing slashes in URLs #9165

Description

@corenominal

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:

$string = 'This is a test link to https://example.com/.';
$html = auto_link($string);
echo $html;

Output:

This is a test link to <a href="https://example.com">https://example.com</a>/.

Expected Output

This is a test link to <a href="https://example.com/">https://example.com/</a>.

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions