Skip to content

fix(ui): don't crash admin render on unparseable custom component route path#17046

Open
yashs33244 wants to merge 1 commit into
payloadcms:mainfrom
yashs33244:fix/admin-components-path-to-regexp
Open

fix(ui): don't crash admin render on unparseable custom component route path#17046
yashs33244 wants to merge 1 commit into
payloadcms:mainfrom
yashs33244:fix/admin-components-path-to-regexp

Conversation

@yashs33244

Copy link
Copy Markdown

What?

When a custom admin component's route path can't be parsed by path-to-regexp (for example a path containing a stray :), isPathMatchingRoute threw an uncaught TypeError: Missing parameter name at N. Because this runs inside the .find() callbacks that match custom-component routes, the throw crashed the entire admin server render. This change catches the parse error and falls back to a literal path comparison.

Why?

This is the root cause behind #15241: with @payloadcms/plugin-multi-tenant, any custom admin component (views, afterNavLinks, beforeNavLinks, ...) could surface a route path that path-to-regexp 6.3.0 rejects, and a single bad pattern took down the whole panel with TypeError: Missing parameter name at 5. A pattern that can't be compiled should simply not match, not crash route matching for every page.

How?

Wrapped the pathToRegexp(...).exec(...) call in isPathMatchingRoute in a try/catch. On a parse error, match is null, so the existing fallback (viewRoute = viewPath) does a plain literal comparison: strict equality when exact, and the existing segment-boundary startsWith check otherwise. Because the fallback compares against the full literal pattern, it can't produce greedy false-positive matches. Added regression tests covering the previously-throwing inputs.

Fixes #15241

…te path

A view path that path-to-regexp can't parse (e.g. a stray ':') threw an
uncaught TypeError inside the route-matching find() callbacks, crashing the
whole admin render. Catch the parse error and fall back to a literal path
comparison so the bad pattern just doesn't match instead of taking down the
panel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Missing parameter name at 5 - Custom Admin Components + Multi-Tenant Plugin

1 participant