fix: handle host-prefixed root path in PublicPathMatcher #8

Merged
andrew merged 2 commits from fix/public-path-host-root into main 2026-08-13 16:28:06 -04:00
Member

Bug

With PUBLIC_PATHS='code.digitaladapt.com/,code.digitaladapt.com/public/**', the home page (/) was not treated as public — only paths under /public/ worked.

Root Cause

In PublicPathMatcher::parse(), the host-prefix regex required at least one character after the slash:

if (preg_match('/^([a-z0-9.-]+)(\/.+)$/i', $entry, $m)) {

The \/.+ meant that code.digitaladapt.com/ (where the path is just / with nothing after it) failed to match the regex. The entry then fell through to the str_starts_with($path, '/') check, but $path was still the full string code.digitaladapt.com/ (which doesn't start with /), so the pattern was silently dropped.

Fix

Changed \/.+ to \/.* so a trailing slash alone is accepted as the path /:

if (preg_match('/^([a-z0-9.-]+)(\/.*)$/i', $entry, $m)) {

Tests

Added two new test cases:

  • testDomainPrefixedRootPathMatchesRoot — verifies host/ matches / and nothing else
  • testDomainPrefixedRootWithOtherPatterns — reproduces the exact bug report scenario

All 295 tests pass.

## Bug With `PUBLIC_PATHS='code.digitaladapt.com/,code.digitaladapt.com/public/**'`, the home page (`/`) was not treated as public — only paths under `/public/` worked. ## Root Cause In `PublicPathMatcher::parse()`, the host-prefix regex required **at least one character after the slash**: ```php if (preg_match('/^([a-z0-9.-]+)(\/.+)$/i', $entry, $m)) { ``` The `\/.+` meant that `code.digitaladapt.com/` (where the path is just `/` with nothing after it) failed to match the regex. The entry then fell through to the `str_starts_with($path, '/')` check, but `$path` was still the full string `code.digitaladapt.com/` (which doesn't start with `/`), so the pattern was silently dropped. ## Fix Changed `\/.+` to `\/.*` so a trailing slash alone is accepted as the path `/`: ```php if (preg_match('/^([a-z0-9.-]+)(\/.*)$/i', $entry, $m)) { ``` ## Tests Added two new test cases: - `testDomainPrefixedRootPathMatchesRoot` — verifies `host/` matches `/` and nothing else - `testDomainPrefixedRootWithOtherPatterns` — reproduces the exact bug report scenario All 295 tests pass.
lyra added 1 commit 2026-08-13 14:31:00 -04:00
fix: handle host-prefixed root path in PublicPathMatcher
Tests / test (pull_request) Successful in 1m3s
Sync GitHub / sync (push) Successful in 6s
e3cd8c6739
The host-prefix regex required at least one character after the slash
(/\+.+/), so a pattern like 'code.example.com/' was silently dropped
instead of matching the root path '/'. Changed \+.+ to \+.* so the
trailing slash alone is accepted as the path '/'.

Added tests covering the exact bug scenario from PUBLIC_PATHS
config: 'code.digitaladapt.com/,code.digitaladapt.com/public/**'
andrew approved these changes 2026-08-13 15:42:29 -04:00
Dismissed
andrew added 1 commit 2026-08-13 15:43:57 -04:00
Merge branch 'main' into fix/public-path-host-root
Tests / test (pull_request) Successful in 1m16s
Sync GitHub / sync (push) Successful in 9s
55f8e9e84c
andrew approved these changes 2026-08-13 15:46:03 -04:00
andrew merged commit 7a68c933ce into main 2026-08-13 16:28:06 -04:00
andrew deleted branch fix/public-path-host-root 2026-08-13 16:28:06 -04:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: public/preauth#8