Skip to content

Url::parse removes host from Windows-style file URL #1126

Description

@msrd0

When trying to parse a windows-style file: URL that contains a hostname, that hostname is removed from the resulting URL:

use url::Url; // 2.5.8

fn main() {
    println!("{}", Url::parse("file://irgendwo/I:/m/nirgendwo").unwrap());
    // prints file:///I:/m/nirgendwo
}

When we use a Unix-style URL (file://irgendwo/im/nirgendwo), it is returned unmodified (i.e. including the hostname).

We can, however, construct a Windows-style URL manually using .set_host():

use url::Url; // 2.5.8

fn main() {
    let mut url = Url::parse("file:///I:/m/nirgendwo").unwrap();
    url.set_host(Some("irgendwo"));
    println!("{url}");
    // prints file://irgendwo/I:/m/nirgendwo
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions