DuskSystems / wayfind

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

Router fails to route to more specific options #148

Closed CathalMullan closed 1 month ago

CathalMullan commented 1 month ago

Following test fails.

#[test]
fn test() -> Result<(), Box<dyn Error>> {
    let mut router = Router::new();
    router.insert("/{file}", 1)?;
    router.insert("/{file}.{extension}", 1)?;

    let path = Path::new("/readme")?;
    let search = router.search(&path)?.unwrap();
    assert_eq!(*search.data, 1);
    assert_eq!(search.parameters[0].key, "file");
    assert_eq!(search.parameters[0].value, "readme");

    let path = Path::new("/report.pdf")?;
    let search = router.search(&path)?.unwrap();
    assert_eq!(*search.data, 1);
    assert_eq!(search.parameters[0].key, "file");
    assert_eq!(search.parameters[0].value, "report");
    assert_eq!(search.parameters[1].key, "extension");
    assert_eq!(search.parameters[1].value, "pdf");

    Ok(())
}
▽
╰─ /
   ╰─ {file} ○
           ╰─ .
              ╰─ {extension} ○

We'd expect the second Path to route to /{file}.{extension}, but it routes to /{file} instead.

We need some way to ensure we try deeper nodes on the same 'branch'.