[6.x] Fix is_external for anchor, mailto and tel links in navs - #15082
Open
duncanmcclean wants to merge 2 commits into
Open
[6.x] Fix is_external for anchor, mailto and tel links in navs#15082duncanmcclean wants to merge 2 commits into
duncanmcclean wants to merge 2 commits into
Conversation
`URL::isExternal()` appended a trailing slash to the whole URL, fragment included, so `http://site.test#anchor` became `http://site.test#anchor/` and no longer matched the site URL. It now strips the query string and fragment before comparing, and treats protocol-relative URLs as external. `URL::makeAbsolute()` prepended the site URL to anything without an `http`/`https` scheme, turning `mailto:` and `tel:` links into internal ones. Those are now left alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Member
Author
|
#15083 will fix the PHPStan failures. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes an issue where a navigation item pointing at an anchor on the current site, like
/#anchor, was reported withis_external => trueby the{{ nav }}tag.This was happening because
URL::isExternal()appended a trailing slash to the whole URL, fragment included. The nav item's absolute URL (http://site.test#anchor) becamehttp://site.test#anchor/, which no longer started with the site URL, so it was considered external.This PR fixes it by stripping the query string and fragment before comparing against the site URL.
While in there, I noticed
mailto:andtel:links had the opposite problem — they were being reported as internal. This was becauseURL::makeAbsolute()prepended the site URL to anything without anhttp/httpsscheme, turningmailto:hello@statamic.comintohttp://site.test/mailto:hello@statamic.com. This PR leaves URLs with other schemes alone, and also treats protocol-relative URLs (//statamic.com) as external.Fixes #15081