Matcher has problem matching text
llacroix opened this issue · comments
Here's a route I made
server.get("/test/:id", middleware!{|req|
let id = req.param("id").unwrap();
format!("{}", id.to_string())
});
If you try to browse the url /test/fun.js
get param will only match fun
and not fun.js
. Also if you want to browse the url: /test/fun:time.js
It will not match anything and fail with NotFound.
I guess it's related to this:
nickel.rs/src/router/into_matcher.rs
Line 18 in 2d0e3d0
Ah no, it's the other line.
nickel.rs/src/router/into_matcher.rs
Line 52 in 2d0e3d0
My guess is that somewhere it's matching the whole regex and matching even with dangling char. So that would explain why /test/fun.txt
matches to ['id'] = "fun"
. But somewhere your global regex probably doesn't match for any possible char. And when we add :
. It fails to match the whole route.
nickel.rs/src/router/into_matcher.rs
Line 55 in d7c3093
Ok found it. Well obviously you could make the regex use unicode aware strings so instead of matching a-zA-Z....
it could be as simple as [\w\[\]]*
as a regex or something similar.
You probably want a named capture that look like this: (?P<{}>[\w\s\p{P}\p{Pd}\p{S}--/]*)
It will match any unicode char except "/" including punctuations and such. So it should correctly match anything between "/" and "/".
What I don't understand is why some char will prevent the whole regex from matching and some will match at least the first part of the regex. Because "/test/fun.js" should fail to match "^/test/(?P<id>[,a-zA-Z0-9%_-]*)(\\?[a-zA-Z0-9%_=&-]*)?$"