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

router/ParamsMap: URL wildcard match containing "%2F" cannot be distinguished from "/" #3183

Open
wrl opened this issue Nov 1, 2024 · 4 comments

Comments

@wrl
Copy link

wrl commented Nov 1, 2024

The current ParamsMap implementation always unescapes param values. This means that, in a wildcard match at the end of a URL, the app has no way of distinguishing a slash as a URL separator from a slash that was originally a "%2F".

Example code:

let mut p = leptos_router::params::ParamsMap::new();
p.insert("rest", "/foo/bar/one%2Ftwo/".into());
assert_eq!(p.get_str("rest"), Some("/foo/bar/one/two/"));
@gbj
Copy link
Collaborator

gbj commented Nov 2, 2024

This is an accurate statement.

Could you say more about what the issue is? For example, "I'm trying to parse the string by splitting it apart at / so I want to preserve the escape characters"?

Related discussion re: escaped vs unescaped characters in (query or path) params in #2601 #2602 #2651.

@gbj
Copy link
Collaborator

gbj commented Nov 2, 2024

(Thinking on it a little more, the fact that it's a wildcard segment and specifically the escape code for / is what makes this different from all other cases, I guess.)

@wrl
Copy link
Author

wrl commented Nov 2, 2024

(Thinking on it a little more, the fact that it's a wildcard segment and specifically the escape code for / is what makes this different from all other cases, I guess.)

Yeah, that's it, the wildcard match is all delivered as one string and the app is responsible for splitting it into segments. There's other ways of approaching this – for example, a wildcard segment could instead handle the splitting before inserting into the params map, and then wildcard segments would be Vec<String> or Box<[String]> instead of just String.

@gbj
Copy link
Collaborator

gbj commented Nov 6, 2024

There is also another, very simple solution here: When you have this particular kind of wildcard route, simply parse the URL yourself. It is only a line or two to .strip_prefix("...") from the path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants