ibraheemdev / matchit

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

Leading slashes in routes with catch-all #42

Closed mladedav closed 6 months ago

mladedav commented 11 months ago

When I try to add routes to the router, it allows paths not starting with a forward slash, except when a catch-all is used.

This seems deliberate but I don't see why that is or why other routes not starting with a slash are allowed.

I might be missing something but I'd say that there should only be a slash right before the catch-all or it should be at the start of the route. So *all and foo/*all are both ok but foo/bar*all is not.

Here are some examples of what currently works and what doesn't.

let mut router = matchit::Router::new();
router.insert("a", ()).unwrap();
router.insert(":a", ()).unwrap();
router.insert("b/:b", ()).unwrap();
// Only the following two return errors
router.insert("c/*c", ()).unwrap();
router.insert("*d", ()).unwrap();

I'd be happy to provide a PR, but I want to check first if there are some considerations I'm missing.

ibraheemdev commented 11 months ago

The reason is that a catch-all parameters used to include the slash. Now that they don't this seems reasonable to allow.

mladedav commented 7 months ago

Hi @ibraheemdev, I got around to this but I've seen in some other issues you already have the matching reworked locally so I wonder if contributing here would not be helpful?

ibraheemdev commented 6 months ago

@mladedav I implemented this as part of 0.8. Thanks for following up.