Skip to content

Commit 6b50daa

Browse files
committed
30 tests to go.
1 parent c70d180 commit 6b50daa

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/parser.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,14 @@ impl<'a> Parser<'a> {
894894
let (host, remaining) = Parser::parse_host(input, scheme_type)?;
895895
write!(&mut self.serialization, "{}", host).unwrap();
896896
let host_end = to_u32(self.serialization.len())?;
897+
if remaining.starts_with(":") {
898+
// Port with an empty host
899+
if let Host::Domain(h) = &host {
900+
if h.is_empty() {
901+
return Err(ParseError::EmptyHost);
902+
}
903+
}
904+
}
897905
let (port, remaining) = if let Some(remaining) = remaining.split_prefix(':') {
898906
let scheme = || default_port(&self.serialization[..scheme_end as usize]);
899907
Parser::parse_port(remaining, scheme, self.context)?

src/quirks.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
157157
}
158158
let result = Parser::parse_host(Input::new(new_hostname), SchemeType::from(url.scheme()));
159159
if let Ok((host, _remaining)) = result {
160+
if let Host::Domain(h) = &host {
161+
if h.is_empty() {
162+
// Empty host on special url
163+
if SchemeType::from(url.scheme()).is_special()
164+
// Port with an empty host
165+
||!port(&url).is_empty()
166+
// Empty host with includes credentials
167+
|| !url.username().is_empty()
168+
|| !url.password().unwrap_or(&"").is_empty()
169+
{
170+
return Err(());
171+
}
172+
}
173+
}
160174
url.set_host_internal(host, None);
161175
Ok(())
162176
} else {
@@ -201,7 +215,7 @@ pub fn pathname(url: &Url) -> &str {
201215

202216
/// Setter for https://url.spec.whatwg.org/#dom-url-pathname
203217
pub fn set_pathname(url: &mut Url, new_pathname: &str) {
204-
if !url.cannot_be_a_base() {
218+
if url.cannot_be_a_base() {
205219
return;
206220
}
207221
if !SchemeType::from(url.scheme()).is_special()

0 commit comments

Comments
 (0)