Issue #3588155: Fix DomainAliasStorage pattern sort comparator and port-pattern priority
Summary
Three changes in domain_alias/src/DomainAliasStorage.php:
sort()never returned-1souasort()never moved patterns up the list. Replaced with a spaceship-operator comparator that actually sorts by specificity (fewer wildcards first, longer string as tiebreaker).buildPortPatterns()emitted variants in the wrong priority order sopattern:*shadowed barepattern. Reordered so hostname-only patterns are emitted first, then port-bearing ones (with:portbefore:*).- Test coverage extended:
DomainAliasSortTestnow asserts the full ordered output ofgetPatterns()rather than just presence, locking in the priority guarantee against future regressions.
Issue: #3588155.
Background
These two bug fixes were originally bundled inside MR !358 (merged) (resolver refactor, issue #3583423) but they're unrelated to that work and were split out for independent review. See the issue body for the full diagnosis.
Release notes
Behavior change worth surfacing in the Domain 3.1.0 release notes:
In
domain_alias, the alias-pattern matcher now respects specificity. A bare-hostname alias (e.g.staging.example.com) wins over a:*alias (e.g.staging.example.com:*) on the same hostname when no explicit port is given, and an explicit-port alias (e.g.staging.example.com:8080) wins over:*on the same port. Sites that previously relied on the buggy:*-first ordering should review their alias config — the new ordering is what the surrounding documentation and docblocks already claim.
Test plan
- Updated
DomainAliasSortTestpasses locally (Drupal 11.x + MySQL). - PHPCS / PHPStan / cspell / eslint / stylelint clean.
- CI phpunit run (re-triggered by the new push).
- Spot-check on a live multi-alias setup — verify a bare-hostname alias now wins over
:*when no explicit port is supplied.
Commits
b702d05a—fix: DomainAliasStorage::sort() never returned -1, breaking sort orderb765831b—fix: DomainAliasStorage::buildPortPatterns() emits patterns in priority order82c933e7—docs: clarify why bare-hostname patterns are omitted on non-default ports2389c39b—test: lock in DomainAliasStorage::getPatterns() priority order