fix: anchor function not updating hostname when Config\App::$allowedHostnames is set#9492
fix: anchor function not updating hostname when Config\App::$allowedHostnames is set#9492devunee wants to merge 2 commits intocodeigniter4:developfrom
Conversation
Fixes function "anchor" not updating the hostname even when it is set in Config\App::$allowedHostnames and when the current URL matches.
|
Hi there, @devunee! 👋 Thank you for sending this PR! We expect the following in all Pull Requests (PRs).
Important We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works. If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md Sincerely, the mergeable bot 🤖 |
|
Hey @devunee, can you add some tests to confirm that your fix is working as intended? |
|
Closing as abandoned. If this is still needed, please open a new PR with tests. Thanks! |
Description
When you have set Config\App::$allowedHostnames the hostname should be set in it if the current URL matches. This is working as expected with with the functions base_url and site_url but NOT working with anchor.
It isn't working as expected because when the anchor function is called with a NULL $altConfig parameter, this parameter is modified to the default Config\App value, then it calls site_url and SiteUri::siteUrl with the default Config\App value instead of NULL which causes the line of code that checks for the host and updates it to be ignored.
The fix is quite simple, the function anchor should keep the parameter $altConfig as NULL and do not modify it to the default Config\App value because this will be done by the SiteUri::siteUrl function.
Checklist: