Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-special domain is never an Ipv4 #803

Closed
samuelcolvin opened this issue Nov 4, 2022 · 2 comments
Closed

non-special domain is never an Ipv4 #803

samuelcolvin opened this issue Nov 4, 2022 · 2 comments

Comments

@samuelcolvin
Copy link

samuelcolvin commented Nov 4, 2022

The following code fails on the final assert:

use url::{Url, Host};

fn main () {
  let u = Url::parse("http://[::1]").unwrap();
  assert_eq!(u.host(), Some(Host::Ipv6("::1".parse().unwrap())));
  
  let u = Url::parse("http://127.0.0.1").unwrap();
  assert_eq!(u.host(), Some(Host::Ipv4("127.0.0.1".parse().unwrap())));
  
  let u = Url::parse("foo://[::1]").unwrap();
  assert_eq!(u.host(), Some(Host::Ipv6("::1".parse().unwrap())));
  
  let u = Url::parse("foo://127.0.0.1").unwrap();
  assert_eq!(u.host(), Some(Host::Ipv4("127.0.0.1".parse().unwrap())));
}

With:

  left: `Some(Domain("127.0.0.1"))`,
 right: `Some(Ipv4(127.0.0.1))`', src/main.rs:14:3

I think this is a bug, I think the behaviour should be the same as for a v6 ip address.

@valenting
Copy link
Collaborator

valenting commented Nov 6, 2022

According to the URL standard non-special URLs are parsed using the opaque host parser. That means the host is just a string, not an IPv4 address.

To exemplify, see parsing foo vs http. http:// rejects an invalid IPv4, whereas foo:// does not (because it parses it as a string)

@samuelcolvin
Copy link
Author

Interesting, thanks for clarifying.

Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants