servo / rust-url

URL parser for Rust
https://docs.rs/url/
Apache License 2.0
1.27k stars 317 forks source link

Fix `serde::Deserialize` impl for `Url` prints confusing error message #861

Open justy777 opened 11 months ago

justy777 commented 11 months ago

When failing to deserialize a str into a Url the current implementation of Deserialize returns an error with a confusing message.

For example:

use serde_json::{json, Result};
use url::Url;

let json = json!("bad_url");
let result: Result<Url> = serde_json::from_value(json);
println!("{}", result.err().unwrap());

Actual: invalid value: string "bad_url", expected relative URL without a base Expected: invalid value: string "bad_url", expected a string representing a URL