summaryrefslogtreecommitdiff
path: root/src/de/parse.rs
diff options
context:
space:
mode:
authorSam Scott <sam@osohq.com>2022-03-05 21:19:28 -0600
committerSam Scott <sam@osohq.com>2022-03-05 21:25:17 -0600
commit4bd3699faba3f00dd8f59a358605abb6e485deb9 (patch)
tree3570c30f8e8f6cd4a1aa1e9b7ec1bf2330c9d33a /src/de/parse.rs
parent58c1832578a103498b0120469b7a5d84833ad1b5 (diff)
Add error message hint for strict mode.
Diffstat (limited to 'src/de/parse.rs')
-rw-r--r--src/de/parse.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/de/parse.rs b/src/de/parse.rs
index a466e5a..5c85b12 100644
--- a/src/de/parse.rs
+++ b/src/de/parse.rs
@@ -1,5 +1,8 @@
+use crate::ser::{replace_space, QS_ENCODE_SET};
+
use super::*;
+use percent_encoding::percent_encode;
use serde::de;
use std::borrow::Cow;
@@ -25,8 +28,17 @@ impl<'a> Level<'a> {
if let Level::Nested(ref mut map) = *self {
match map.entry(key) {
Entry::Occupied(mut o) => {
+ let key = o.key();
+ let error = if key.contains('[') {
+ let newkey = percent_encode(key.as_bytes(), QS_ENCODE_SET)
+ .map(replace_space)
+ .collect::<String>();
+ format!("Multiple values for one key: \"{}\"\nInvalid field contains an encoded bracket -- did you mean to use non-strict mode?\n https://docs.rs/serde_qs/latest/serde_qs/#strict-vs-non-strict-modes", newkey)
+ } else {
+ format!("Multiple values for one key: \"{}\"", key)
+ };
// Throw away old result; map is now invalid anyway.
- let _ = o.insert(Level::Invalid("Multiple values for one key"));
+ let _ = o.insert(Level::Invalid(error));
}
Entry::Vacant(vm) => {
// Map is empty, result is None
@@ -40,7 +52,8 @@ impl<'a> Level<'a> {
} else {
*self = Level::Invalid(
"Attempted to insert map value into \
- non-map structure",
+ non-map structure"
+ .to_string(),
);
}
}
@@ -51,7 +64,7 @@ impl<'a> Level<'a> {
match map.entry(key) {
Entry::Occupied(mut o) => {
// Throw away old result; map is now invalid anyway.
- let _ = o.insert(Level::Invalid("Multiple values for one key"));
+ let _ = o.insert(Level::Invalid("Multiple values for one key".to_string()));
}
Entry::Vacant(vm) => {
// Map is empty, result is None
@@ -66,7 +79,8 @@ impl<'a> Level<'a> {
} else {
*self = Level::Invalid(
"Attempted to insert seq value into \
- non-seq structure",
+ non-seq structure"
+ .to_string(),
);
}
}
@@ -85,7 +99,8 @@ impl<'a> Level<'a> {
} else {
*self = Level::Invalid(
"Attempted to insert seq value into \
- non-seq structure",
+ non-seq structure"
+ .to_string(),
);
}
}