Skip to content

Commit ae8b86a

Browse files
committed
36 tests to go.
1 parent ed718fb commit ae8b86a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/host.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ impl<'de> ::serde::Deserialize<'de> for HostInternal {
6060
}
6161
}
6262

63-
impl<S> From<Host<S>> for HostInternal {
63+
impl<S> From<Host<S>> for HostInternal
64+
where
65+
S: ToString,
66+
{
6467
fn from(host: Host<S>) -> HostInternal {
6568
match host {
69+
Host::Domain(ref s) if s.to_string().is_empty() => HostInternal::None,
6670
Host::Domain(_) => HostInternal::Domain,
6771
Host::Ipv4(address) => HostInternal::Ipv4(address),
6872
Host::Ipv6(address) => HostInternal::Ipv6(address),

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ impl<'a> Parser<'a> {
949949
host_str = &input_str[..bytes]
950950
}
951951
}
952-
if scheme_type.is_special() && host_str.is_empty() {
952+
if scheme_type == SchemeType::SpecialNotFile && host_str.is_empty() {
953953
return Err(ParseError::EmptyHost);
954954
}
955955
if !scheme_type.is_special() {

src/quirks.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
122122
Err(_) => return Err(()),
123123
}
124124
}
125+
// Make sure we won't set an empty host to a url with a username or a port
126+
if host == Host::Domain("".to_string()) {
127+
if !username(&url).is_empty() {
128+
return Err(());
129+
}
130+
if let Some(p) = opt_port {
131+
if let Some(_) = p {
132+
return Err(());
133+
}
134+
}
135+
if url.port().is_some() {
136+
return Err(());
137+
}
138+
}
125139
url.set_host_internal(host, opt_port);
126140
Ok(())
127141
}

0 commit comments

Comments
 (0)