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

[DISC] Percent decoding #98

Closed
erwanvivien opened this issue Feb 22, 2022 · 5 comments
Closed

[DISC] Percent decoding #98

erwanvivien opened this issue Feb 22, 2022 · 5 comments

Comments

@erwanvivien
Copy link

erwanvivien commented Feb 22, 2022

Hello everyone,

Could we have a feature where from_str returns values with no parsing ?

use std::collections::HashMap;
use serde_urlencoded::from_str; // 0.7.1

let query_string = "id=6%206&abc=123&def=2%252";
let query_string = query_string.replace("%", "%25");

let map = from_str::<HashMap<String, String>>(&query_string).unwrap();

println!("{:?}", map);

Which yield

{"id": "6%206", "def": "2%252", "abc": "123"}

I'm using the above code for now to escape '%' character

Sorry if issue isn't the best suited place.

Thanks

Edit: added output

@nox
Copy link
Owner

nox commented Feb 23, 2022

You probably want to file an issue at https://github.com/servo/rust-url/ and use the percent_encoding crate directly.

@nox nox closed this as completed Feb 23, 2022
@ckcr4lyf
Copy link

@erwanvivien wondering if you were able to come across a solution? Thanks to your hack I am able to get my current code working (i.e no invalid UTF8 error), but receiving raw bytes in URL params is proving to be a problem to otherwise decode currently...

Current hack (inspired by yours: ckcr4lyf/kiryuu@2536307#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR29)

@erwanvivien
Copy link
Author

Hello @ckcr4lyf,

I'm still, to this day, using the said "hack"...
I do not understand @nox answer, serde_urlencode doesn't use https://github.com/servo/rust-url/ ?

Why is there no function to decode only the keys, not the values ?

id=6%206&abc=123&def=2%252 yieding {"id": "6%206", "def": "2%252", "abc": "123"} as mentionned before.

Thanks

@ckcr4lyf
Copy link

I am not too sure myself, I wasn't really able to read the source that well... I will try and figure out if the % decoding is an issue at this library's usage of rust-url or it comes due to a higher level issue of auto decoding in rust-url

@ckcr4lyf
Copy link

@erwanvivien seems it is a design choice by the parent library to not support invalid UTF-8, as is mentioned in this spec which they follow - https://url.spec.whatwg.org/#urlencoded-parsing

Guess no choice except the hack, thanks for sharing it!

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

3 participants