Skip to content

Conversation

@devunee
Copy link

@devunee devunee commented Mar 15, 2025

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:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Fixes function "anchor" not updating the hostname even when it is set in Config\App::$allowedHostnames and when the current URL matches.
@mergeable
Copy link

mergeable bot commented Mar 15, 2025

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
on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

Sincerely, the mergeable bot 🤖

@devunee devunee changed the title Small fix for anchor function (fix) for anchor function Mar 15, 2025
@devunee devunee changed the title (fix) for anchor function fix: anchor function not updating hostname when Config\App::$allowedHostnames is set Mar 15, 2025
@paulbalandan paulbalandan added the tests needed Pull requests that need tests label Mar 16, 2025
@paulbalandan
Copy link
Member

Hey @devunee, can you add some tests to confirm that your fix is working as intended?

@paulbalandan
Copy link
Member

Closing as abandoned. If this is still needed, please open a new PR with tests. Thanks!

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

Labels

tests needed Pull requests that need tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants