mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 21:37:58 +03:00
fix str path deserializer
This commit is contained in:
parent
75deae2fd4
commit
0f89a586b1
1 changed files with 17 additions and 2 deletions
|
@ -182,13 +182,13 @@ impl<'de, T: ResourcePath + 'de> Deserializer<'de> for PathDeserializer<'de, T>
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
if self.path.len() != 1 {
|
if self.path.len() < 1 {
|
||||||
Err(de::value::Error::custom(
|
Err(de::value::Error::custom(
|
||||||
format!("wrong number of parameters: {} expected 1", self.path.len())
|
format!("wrong number of parameters: {} expected 1", self.path.len())
|
||||||
.as_str(),
|
.as_str(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
visitor.visit_str(&self.path[0])
|
visitor.visit_borrowed_str(&self.path[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,6 +562,10 @@ mod tests {
|
||||||
assert_eq!(s.0, "name");
|
assert_eq!(s.0, "name");
|
||||||
assert_eq!(s.1, "user1");
|
assert_eq!(s.1, "user1");
|
||||||
|
|
||||||
|
let s: &str =
|
||||||
|
de::Deserialize::deserialize(PathDeserializer::new(&path)).unwrap();
|
||||||
|
assert_eq!(s, "name");
|
||||||
|
|
||||||
let mut path = Path::new("/name/user1/");
|
let mut path = Path::new("/name/user1/");
|
||||||
path.segments = vec![
|
path.segments = vec![
|
||||||
("key", PathItem::Static("name")),
|
("key", PathItem::Static("name")),
|
||||||
|
@ -707,5 +711,16 @@ mod tests {
|
||||||
de::Deserialize::deserialize(PathDeserializer::new(&path));
|
de::Deserialize::deserialize(PathDeserializer::new(&path));
|
||||||
assert!(s.is_err());
|
assert!(s.is_err());
|
||||||
assert!(format!("{:?}", s).contains("missing field `inner`"));
|
assert!(format!("{:?}", s).contains("missing field `inner`"));
|
||||||
|
|
||||||
|
let path = Path::new("");
|
||||||
|
let s: Result<&str, de::value::Error> =
|
||||||
|
de::Deserialize::deserialize(PathDeserializer::new(&path));
|
||||||
|
assert!(s.is_err());
|
||||||
|
assert!(format!("{:?}", s).contains("wrong number of parameters: 0 expected 1"));
|
||||||
|
|
||||||
|
let s: Result<TestEnum, de::value::Error> =
|
||||||
|
de::Deserialize::deserialize(PathDeserializer::new(&path));
|
||||||
|
assert!(s.is_err());
|
||||||
|
assert!(format!("{:?}", s).contains("expeceted at least one parameters"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue