Skip to content

馃Ч [Maintenance]: share the route parameter delimiter set between router and client#4635

Description

@ReneWerner87

Maintenance Task Description

client/hooks.go defines pathParamEndChars, the byte set that terminates a :name placeholder in a request URL. It is a hand-written copy of the router's parameterEndChars (path.go:171), and its own comment says so: "The set mirrors the route parser's parameterEndChars (path.go)".

The two sets are identical today except for #, which only the client needs:

only in router: []
only in client: ['#']

Nothing in the code connects them. The only reference to parameterEndChars outside path.go in the entire repository is that comment. Both identifiers are unexported and live in different packages, so no test can compare them without one of them moving first.

Proposal: move the shared delimiters into an internal package, have path.go and client/hooks.go both build their sets from it, and add the drift test that then becomes possible. The repo already has this pattern in internal/urlnorm, internal/schemehost and internal/mediatype.

Impact on the Project

Change the router's placeholder grammar and the client keeps the old one, silently. Nothing fails loudly, because an unresolved placeholder is left in the URL verbatim rather than reported, so the request goes out with a literal :name in it and the server answers 404.

That failure mode already happened once: in #4625 a change to the client's own delimiter handling stopped resolving every parameter whose name contained -, . or :, and the full test suite stayed green.

Scope note: only the delimiter set is worth sharing. The two parsers do opposite things. The router turns a pattern into routeSegment values with constraints and optional flags to build a matcher; the client scans a finished URL and substitutes values into it. Since #4625 the client also resolves the longest registered name, which the router does not do. A shared package should therefore hold the byte set and nothing else, and the comment in client/hooks.go should stop suggesting that the two resolve placeholders the same way.

Additional Context

Came out of the review of #4625. There is no package boundary in the way: the client already imports the root package (client/core.go:15, client/request.go:17, for fiber.MethodGet and friends). parameterEndChars is simply unexported, and exporting it would put a routing internal into the public API, which is why an internal package is the better shape.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions