فهرست منبع

url: allow setting host or hostname to empty on file URLs

Per the tests in https://github.com/web-platform-tests/wpt/pull/5112.
Dirkjan Ochtman 6 سال پیش
والد
کامیت
52ba6972a2
1فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 10 0
      src/quirks.rs

+ 10 - 0
src/quirks.rs

@@ -111,6 +111,11 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
     {
         let scheme = url.scheme();
         let scheme_type = SchemeType::from(scheme);
+        if scheme_type == SchemeType::File && new_host.is_empty() {
+            url.set_host_internal(Host::Domain(String::new()), None);
+            return Ok(());
+        }
+
         if let Ok((h, remaining)) = Parser::parse_host(input, scheme_type) {
             host = h;
             opt_port = if let Some(remaining) = remaining.split_prefix(':') {
@@ -160,6 +165,11 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
     // Host parsing rules are strict we don't want to trim the input
     let input = Input::no_trim(new_hostname);
     let scheme_type = SchemeType::from(url.scheme());
+    if scheme_type == SchemeType::File && new_hostname.is_empty() {
+        url.set_host_internal(Host::Domain(String::new()), None);
+        return Ok(());
+    }
+
     if let Ok((host, _remaining)) = Parser::parse_host(input, scheme_type) {
         if let Host::Domain(h) = &host {
             if h.is_empty() {