diff options
author | Sam Scott <sam@osohq.com> | 2020-12-06 21:25:32 -0500 |
---|---|---|
committer | Sam Scott <sam@osohq.com> | 2020-12-06 21:25:32 -0500 |
commit | 8453323aaf7e35b3c01b16e54d10f255d465b29c (patch) | |
tree | fe9a9a3d0eabde4ca9bc5ecc8ace56f7fd32ed4e | |
parent | 4ccebebc59a0f24a5821cc8144f035d75f2eaa75 (diff) |
Remove extra incorrect replace_spaces in key serialization.
Fixes #38
Thanks to @pooyamb for reporting.
-rw-r--r-- | src/ser.rs | 3 | ||||
-rw-r--r-- | tests/test_regression.rs | 25 |
2 files changed, 27 insertions, 1 deletions
@@ -124,7 +124,8 @@ fn replace_space(input: &str) -> Cow<str> { impl<'a, W: 'a + Write> QsSerializer<'a, W> { fn extend_key(&mut self, newkey: &str) { let newkey = - percent_encode(replace_space(newkey).as_bytes(), QS_ENCODE_SET).collect::<Cow<str>>(); + percent_encode(newkey.as_bytes(), QS_ENCODE_SET) + .collect::<Cow<str>>(); let key = if let Some(ref key) = self.key { format!("{}[{}]", key, newkey).into() } else { diff --git a/tests/test_regression.rs b/tests/test_regression.rs new file mode 100644 index 0000000..7d2f492 --- /dev/null +++ b/tests/test_regression.rs @@ -0,0 +1,25 @@ +extern crate serde; +#[macro_use] +extern crate serde_derive; +extern crate serde_qs as qs; + +#[test] +fn double_encoding_keys() { + #[derive(Debug, 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).unwrap(); + print!("{}", encoded); + assert_eq!( + serde_qs::from_str::<Human>(&encoded) + .unwrap(), + human + ); +} |