DuskSystems / wayfind

A speedy, flexible router for Rust.
Apache License 2.0
10 stars 0 forks source link

Decide on how to handle routes that begin with optional groups #164

Closed CathalMullan closed 1 week ago

CathalMullan commented 1 month ago

(/{page}) results in "" and "/{page}" being inserted into the router currently.

We don't allow raw empty routes, so should we error if a route expands to an empty route?

If we require that all routes should start with a /, this wouldn't be an issue. Would that be the better option?

Axum requires all routes to start with /, but AFAIK this isn't due to a matchit decision, but to ensure catch alls work properly for them.

Rails doesn't.

I don't like the idea of rewriting the users routes. Either we reject any empty routes OR we filter them out?

Does GitLab make use of empty expanded routes anywhere?

Since Rust HTTP auto-converts empty to "/", we should do the same here.

pub fn path(&self) -> &str {
    let ret = if self.query == NONE {
        &self.data[..]
    } else {
        &self.data[..self.query as usize]
    };

    if ret.is_empty() {
        return "/";
    }

    ret
}