http-rs / http-rs/route-recognizer

Duplicate named parameters in route

Open
#34 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
101
Forks
35
PR merge metrics
No merged PRs in 30d

Description

You can currently define duplicate named parameters in the route with the last one resolved being the end value. E.g. given the following:

```rust
#[test]
fn duplicate_key() {
let mut router = Router::new();

router.add("/foo/:bar/*bar", "test".to_string());
let m = router.recognize("/foo/blah/this/is/the/rest").unwrap();
assert_eq!(*m.handler, "test".to_string());
assert_eq!(m.params, params("bar", "blah"));
}
```

this fails with:
```
thread 'duplicate_key' panicked at 'assertion failed: `(left == right)`
left: `Params { map: {"bar": "this/is/the/rest"} }`,
right: `Params { map: {"bar": "blah"} }`', src\lib.rs:339:5
```

This should probably be prevented when the route is created - given that you can define nameless parameters I can't see a reason for needing to have duplicate names.

Contributor guide

Open the contributing guide

Research direction

Start in src/lib.rs around the route creation and the duplicate_key test context shown in the issue. Trace how named and wildcard parameters are stored when a route is added, then verify the behavior for repeated names. Done means duplicate parameter names are prevented at route creation and the relevant test confirms the intended result.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.