Issue #3588155: Fix DomainAliasStorage pattern sort comparator and port-pattern priority

Summary

Three changes in domain_alias/src/DomainAliasStorage.php:

  1. sort() never returned -1 so uasort() never moved patterns up the list. Replaced with a spaceship-operator comparator that actually sorts by specificity (fewer wildcards first, longer string as tiebreaker).
  2. buildPortPatterns() emitted variants in the wrong priority order so pattern:* shadowed bare pattern. Reordered so hostname-only patterns are emitted first, then port-bearing ones (with :port before :*).
  3. Test coverage extended: DomainAliasSortTest now asserts the full ordered output of getPatterns() 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 DomainAliasSortTest passes 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

  • b702d05afix: DomainAliasStorage::sort() never returned -1, breaking sort order
  • b765831bfix: DomainAliasStorage::buildPortPatterns() emits patterns in priority order
  • 82c933e7docs: clarify why bare-hostname patterns are omitted on non-default ports
  • 2389c39btest: lock in DomainAliasStorage::getPatterns() priority order
Edited by Frank Mably

Merge request reports

Loading