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

Mixing prefixes and suffixes can lead to ambiguous routes #67

Open
ibraheemdev opened this issue Jan 3, 2025 · 1 comment
Open

Mixing prefixes and suffixes can lead to ambiguous routes #67

ibraheemdev opened this issue Jan 3, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ibraheemdev
Copy link
Owner

Pointed out in tokio-rs/axum#3140. Quoting from there:

I think there are three cases to consider:

  1. /prefix{wild} and {wild}suffix

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.

  1. /prefix{wild} and prefix{wild}suffix
  2. /{wild}suffix and prefix{wild}suffix

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.

  • /prefixsuffi{x} and prefix{s}uffix
  • /{p}refixsuffix and prefix{s}uffix

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.

@ibraheemdev ibraheemdev added the bug Something isn't working label Jan 3, 2025
@ibraheemdev
Copy link
Owner Author

Work in progress on this branch that implements the new rules:

A given list of overlapping route segments can include, in order of priority,

  • Any number of static segments (/a, /b, ..).
  • One of the following:
    • Any number of parameters with suffixes (/{x}a, /{x}b, ..), prioritizing the longest suffix.
    • Any number of parameters with prefixes (/a{x}, /b{x}, ..), prioritizing the longest prefix.
    • A single parameter with both a prefix and a suffix (/a{x}b).
  • A single parameter without a suffix or prefix (/{x}).

In short, any prefix conflicts with a suffix, and vice versa. However, there are a number of different cases to check when inserting and the code also has to be restructured a little bit to keep track of parent and sibling nodes while inserting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant