Skip to content

Commit

Permalink
Fix #861 serde::Deserialize impl for Url prints confusing error message
Browse files Browse the repository at this point in the history
  • Loading branch information
justy777 committed Oct 4, 2023
1 parent a08aa2c commit 5056a0a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions url/src/lib.rs
Expand Up @@ -2775,16 +2775,15 @@ impl<'de> serde::Deserialize<'de> for Url {
type Value = Url;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a string representing an URL")
formatter.write_str("a string representing a URL")
}

fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
where
E: Error,
{
Url::parse(s).map_err(|err| {
let err_s = format!("{}", err);
Error::invalid_value(Unexpected::Str(s), &err_s.as_str())
Url::parse(s).map_err(|_| {
Error::invalid_value(Unexpected::Str(s), &self)
})
}
}
Expand Down

0 comments on commit 5056a0a

Please sign in to comment.