samscott89 / serde_qs

Serde support for querystring-style strings
Apache License 2.0
193 stars 68 forks source link

Bug report: Double encoding keys in serializer #38

Closed pooyamb closed 3 years ago

pooyamb commented 3 years ago

It looks like serializer is doing percent encoding twice.

Minimal reproducible test that fails:

#[derive(Debug, serde::Serialize, Deserialize, PartialEq)]
struct Human {
    #[serde(rename = "full name")]
    name: String,
}

let human = Human {
    name: "John Doe".to_string(),
};

let encoded = serde_qs::to_string(&human);

assert_eq!(
    encoded
        .and_then(|string| serde_qs::from_str::<Human>(&string))
        .unwrap(),
    human
);

Cause: I guess it encodes the space in field's name to + and encodes it again later to %2B.

samscott89 commented 3 years ago

Thank you for reporting this, and especially for providing the helpful test case. Fixed this, and will be pushing a minor release with the fix.