Skip to content

Commit 52ba697

Browse files
committed
url: allow setting host or hostname to empty on file URLs
Per the tests in web-platform-tests/wpt#5112.
1 parent 5937812 commit 52ba697

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/quirks.rs

+10
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
111111
{
112112
let scheme = url.scheme();
113113
let scheme_type = SchemeType::from(scheme);
114+
if scheme_type == SchemeType::File && new_host.is_empty() {
115+
url.set_host_internal(Host::Domain(String::new()), None);
116+
return Ok(());
117+
}
118+
114119
if let Ok((h, remaining)) = Parser::parse_host(input, scheme_type) {
115120
host = h;
116121
opt_port = if let Some(remaining) = remaining.split_prefix(':') {
@@ -160,6 +165,11 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
160165
// Host parsing rules are strict we don't want to trim the input
161166
let input = Input::no_trim(new_hostname);
162167
let scheme_type = SchemeType::from(url.scheme());
168+
if scheme_type == SchemeType::File && new_hostname.is_empty() {
169+
url.set_host_internal(Host::Domain(String::new()), None);
170+
return Ok(());
171+
}
172+
163173
if let Ok((host, _remaining)) = Parser::parse_host(input, scheme_type) {
164174
if let Host::Domain(h) = &host {
165175
if h.is_empty() {

0 commit comments

Comments
 (0)