servo / rust-url

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

Incorrect error when url contains number sign #922

Closed agirorn closed 3 months ago

agirorn commented 3 months ago

When I parse url with an invalid character like the # sign in the password part of the url I get Err(InvalidPort) error but I think I should be getting a more helpful error like InvalidPassword for instance

    let parsed = Url::parse("postgres://user:pa#ss@host:9999/database");
    println!("{:#?}", parsed);
Err(
    InvalidPort,
)
valenting commented 3 months ago

The error is actually correct. Because the # is present in the password, the user is now parsed as a host, while pa is parsed as a port and fails. If you change the URL to postgres://user:12#ss... it will parse.

Check out the reference URL parser here