Skip to content

Split path components that contain a slash when registering routes - #157

Open
dioKaratzas wants to merge 2 commits into
vapor:mainfrom
dioKaratzas:fix/slashes-in-path-components
Open

dioKaratzas wants to merge 2 commits into
vapor:mainfrom
dioKaratzas:fix/slashes-in-path-components

Conversation

@dioKaratzas

@dioKaratzas dioKaratzas commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes vapor/vapor#3349. Follow-up to #155: as discussed there, slashes are now parsed at routing build time instead of rejected.

app.get("te/st") used to register a single te/st component, so /te/st returned 404. TrieRouterBuilder.register(_:at:) now splits such components into the ones they spell out, so "users/:id" registers the same as ["users", ":id"]. This covers constants, parameters (":id/edit") and partials (":{name}.md/raw"). Components without a slash are unchanged.

Splitting happens once per route at registration; the lookup code is unchanged.

Covered by a parameterized test in RouterTests. Also checked end to end in Vapor (app.get("te/st"), app.get("users/:id"), app.grouped("api/v1")).

Encoded slashes, checked in Vapor against routing-kit 5.0.0-beta.3 and this branch:

request route before after
/te%2Fst "te/st" 200 404
/te/st "te/st" 404 200
/files/a%2Fb "files", ":name" 200 (a/b) 200 (a/b)
/docs/a%2Fb "docs/:name" 404 200 (a/b)

Summary:
- Register a component like "users/:id" as the components it spells out, the same as ["users", ":id"]
- Handle slashes in constants, parameters and partial parameters
- Cover constants, parameters, catchalls and partials with a parameterized router test
Summary:
- Add a ":{name}.md/raw" case to the slash-splitting router test
@dioKaratzas

Copy link
Copy Markdown
Author

@0xTim @gwynne, one question on encoded slashes. Before this change app.get("te/st") was reachable as /te%2Fst but not /te/st. Now it's the other way round (table in the description).

Should /te%2Fst keep matching a route written with /? RFC 3986 §2.2 treats %2F as data rather than a separator, so I left it as a single segment, but happy to add it if you'd rather keep it working.

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.

PathComponents with slashes are accepted, but are not reachable

1 participant