Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching a mix of dynamic and static routes with overlaps #12

Closed
loony-bean opened this issue Dec 24, 2021 · 2 comments
Closed

Matching a mix of dynamic and static routes with overlaps #12

loony-bean opened this issue Dec 24, 2021 · 2 comments

Comments

@loony-bean
Copy link

Hi @ibraheemdev! First of all, thanks for your work!

I'm trying to match a mix of dynamic and static routes, which have overlapping parts. But not all the cases are matching.

I guess this is better explained with the following code snippet.

#[cfg(test)]
mod tests {
    use matchit::Node;

    #[test]
    fn test_routes() {
        let mut matcher = Node::new();

        matcher.insert("/:object/:id", "object with id").unwrap();
        matcher.insert("/secret/:id/path", "secret with id and path").unwrap();

        let matched = matcher.at("/secret/978/path").unwrap();
        assert_eq!(matched.params.get("id"), Some("978"));

        let matched = matcher.at("/something/978").unwrap();
        assert_eq!(matched.params.get("id"), Some("978"));
        assert_eq!(matched.params.get("object"), Some("something"));

        let _ = matcher.at("/secret/978").unwrap(); // panics
    }
}

It it expected behaviour?

@ibraheemdev
Copy link
Owner

Hi, that is not expected behavior. It looks like the node never backtracks in that case.. I'll look into it.

@ibraheemdev
Copy link
Owner

Fixed in (329e24e). I'll add some more tests and get a patch release out.

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

No branches or pull requests

2 participants