-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update matchit to 0.8.6 #3140
Comments
Thanks for the update. I'll try to take a look at the upgrade here. |
Just to make sure about precedence, So for example from these paths:
This change will lead to a subtle difference between For example the following test behaves differently with the two methods: #[crate::test]
async fn nest_at_prefix_capture() {
let empty_routes = Router::new();
let api_routes = Router::new().route(
"/{b}",
get(|Path((a, b)): Path<(String, String)>| async move { format!("a={a} b={b}") }),
);
let app = Router::new()
.nest("/x{a}x", api_routes)
.nest("/xax", empty_routes);
let client = TestClient::new(app);
let res = client.get("/xax/bar").await;
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(res.text().await, "a=a b=bar");
} if we use
so the second one is chosen. In case of
so the first one is used, inner router of the nested service is called and a default 404 fallback is invoked. |
Yes, that is correct, though I didn't fully consider the implications of mixed suffixes and prefixes. Do you think these routes (or even any two of those routes) should be considered conflicting instead? |
I don't fully understand why this problem is unique to suffixes. Wouldn't the same thing occur if the routes were |
I think this is fine and we can just document the behavior and maybe discourage mixing of prefixes and suffixes in the same node. I can't really think right now about a scenario where I'd use a static prefix, let alone mix prefixes and suffixes. I don't think they need to be considered conflicting, I just wanted to make sure that's how it works.
Right, I did not consider that. So this has always kind of been the case and the update doesn't really change anything in that regard. |
I would prefer to disallow ambiguous routes, that has been my philosophy with most of matchit's requested features so I think it makes sense to be consistent. The current rules are mostly an implementation detail and haven't been thought out or documented. The route I think there are three cases to consider:
This should be considered conflicting. The only way out is to prioritize either prefixes or suffixes, or to prioritize the longer/shorter prefix/suffix and conflict or fallback in the case that they are equal, neither of which seems more intuitive than the other.
This case is a little more nuanced and only ambiguous if the prefixes or suffixes match. It seems reasonable to prefer the second route in both cases, but this may be difficult to implement. It also becomes more unintuitive with mixed length prefixes/suffixes, e.g.
So I think these should also be considered conflicting. Disallowing ambiguous routes within a segment should make the routing rules intuitive and easy to document overall. I can implement these rules and release 0.9.0, which you may want to wait for as it would be a breaking change. Does that seem reasonable? |
If you want to change it, then there's no rush and we can wait for the updated version to prevent breakage. Personally, I'd consider completely omitting having both a prefix and a suffix since I'm still not really convinced that it just doesn't just add complexity, both to resolution and mental overhead. Then you can declare any prefix to be conflicting with any suffix and then it's a simple case where the longest prefix/suffix matches. If And also by having |
Hm yeah this also might be problematic. You might be right that a given list of overlapping route segments can include, in order of priority,
|
Yeah, I think that's good. |
The latest release adds support for parameter suffixes. matchit is currently pinned to 0.8.5 because there was some concern about this being a breaking change but I am not sure about the details. Let me know if there is anything I can do to help with that.
The text was updated successfully, but these errors were encountered: