Fix Deserialize for CrateVersionSource

Use `Cow::<'_, str>::deserialize` to ensure that it would still work
even if it contains escaped characters.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-22 01:43:40 +10:00
parent a3fcc298ab
commit 32b98f0c5a
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -1,4 +1,4 @@
use std::{fmt, str::FromStr};
use std::{borrow::Cow, fmt, str::FromStr};
use miette::Diagnostic;
use once_cell::sync::Lazy;
@ -116,7 +116,7 @@ impl<'de> Deserialize<'de> for CrateVersionSource {
where
D: Deserializer<'de>,
{
let s = <&str>::deserialize(deserializer)?;
Self::from_str(s).map_err(serde::de::Error::custom)
let s = Cow::<'_, str>::deserialize(deserializer)?;
Self::from_str(&s).map_err(serde::de::Error::custom)
}
}