ibraheemdev / matchit

A high performance, zero-copy URL router.
https://docs.rs/matchit
MIT License
366 stars 37 forks source link

Support escaping `:` and `*` #23

Closed hgzimmerman closed 8 months ago

hgzimmerman commented 2 years ago

I'm using this library by proxy of Axum, and ran into an issue in that the router would not accept path segments that contained multiple : characters, greeting me with the error: Invalid route "/Schemas/urn:ietf:params:scim:schemas:core:2.0:User": only one parameter is allowed per path segment, corresponding to the TooManyParams error variant defined in this crate.

Could either the syntax be altered to support escaping the : and * characters with a prefix like \, or have the insert method treat the whole path section as a literal if it doesn't start with a : or *, or add an .insert_components() function that takes a slice of enum Component<'a>{Literal(&'a str), Param, Wildcard, Separator} and uses that to determine the matching criteria?

ibraheemdev commented 2 years ago

I think escaping with \ makes sense. /prefix:parameter is accepted by matchit, which makes the second option more difficult.

DavidSouther commented 2 years ago

Just opened this (and linked) from Axum. I would also like to propose using /{id} for path pattern matching, to align with the OpenAPI spec.

ibraheemdev commented 8 months ago

With the release of 0.8, the route parameter syntax has changed to use {x} or {*x}. You can escape literal { and } characters with {{ and }} in static routes.