Skip to content

fix(Helpers): strip port before evaluating subdomain in parse_subdomain() - #10794

Merged
paulbalandan merged 1 commit into
codeigniter4:developfrom
banghamid:fix/url-helper-parse-subdomain-port
Nov 21, 2026
Merged

paulbalandan merged 1 commit into
codeigniter4:developfrom
banghamid:fix/url-helper-parse-subdomain-port

Conversation

@banghamid

Copy link
Copy Markdown
Contributor

Description
In url_helper.php, parse_subdomain(?string $host = null) did not account for port numbers in the host string (such as when explicitly provided, or passed from $_SERVER['HTTP_HOST']).

This caused several issues:

  1. An IP address with a port (e.g. '192.168.1.1:8080') failed FILTER_VALIDATE_IP and was treated as a domain with 4 dot-separated parts, erroneously returning '192.168' as a subdomain.
  2. Two-part TLD domains with a port (e.g. 'example.co.uk:8080') failed matching in Hostnames::TWO_PART_TLDS because $lastTwoParts was 'co.uk:8080', causing it to fall back to the standard 2-part removal and erroneously returning 'example' as a subdomain.
  3. Subdomains on two-part TLD domains with a port (e.g. 'api.example.co.uk:8080') returned 'api.example' instead of 'api'.

This PR handles bracketed IPv6 literals (e.g. '[::1]:8080') and strips single-colon port suffixes before evaluating IP addresses, localhost, and TLD boundaries in parse_subdomain(). It also adds test cases to provideParseSubdomain() in MiscUrlTest and adds a changelog entry in docs/changelogs/v4.7.7.md.

Checklist:

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

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 19, 2026
@paulbalandan

Copy link
Copy Markdown
Member

Please rebase

@carson-codeigniter4 carson-codeigniter4 Bot added the stale Pull requests with conflicts label Nov 20, 2026
@carson-codeigniter4

This comment has been minimized.

@banghamid
banghamid force-pushed the fix/url-helper-parse-subdomain-port branch from ecf74d6 to 519eccd Compare November 20, 2026 17:33
@carson-codeigniter4 carson-codeigniter4 Bot removed the stale Pull requests with conflicts label Nov 20, 2026
@paulbalandan paulbalandan changed the title fix(Helpers): strip port before evaluating subdomain in parse_subdomain() fix(Helpers): strip port before evaluating subdomain in parse_subdomain() Nov 20, 2026
@paulbalandan
paulbalandan merged commit ff76fcf into codeigniter4:develop Nov 21, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants