Skip to content

Commit f3e1331

Browse files
committed
Fix dropping of host during file url conversion
1 parent 2344f91 commit f3e1331

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

gix-url/src/parse/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn find_scheme(input: &BStr) -> InputScheme {
8383
/// For file-paths, we don't expect UTF8 encoding either.
8484
pub fn parse(input: &BStr) -> Result<crate::Url, Error> {
8585
match find_scheme(input) {
86-
InputScheme::Local => parse_local(input, false),
86+
InputScheme::Local => parse_local(input),
8787
InputScheme::Url { protocol_end } if input[..protocol_end].eq_ignore_ascii_case(b"file") => {
8888
parse_file_url(input, protocol_end)
8989
}
@@ -172,10 +172,14 @@ fn parse_file_url(input: &BStr, protocol_colon: usize) -> Result<crate::Url, Err
172172
});
173173
}
174174

175-
parse_local(url.path().into(), true)
175+
Ok(crate::Url {
176+
serialize_alternative_form: false,
177+
host: url.host_str().map(Into::into),
178+
..parse_local(url.path().into())?
179+
})
176180
}
177181

178-
fn parse_local(input: &BStr, was_in_url_format: bool) -> Result<crate::Url, Error> {
182+
fn parse_local(input: &BStr) -> Result<crate::Url, Error> {
179183
if input.is_empty() {
180184
return Err(Error::MissingRepositoryPath {
181185
url: input.to_owned(),
@@ -184,7 +188,7 @@ fn parse_local(input: &BStr, was_in_url_format: bool) -> Result<crate::Url, Erro
184188
}
185189

186190
Ok(crate::Url {
187-
serialize_alternative_form: !was_in_url_format,
191+
serialize_alternative_form: true,
188192
scheme: crate::scheme::Scheme::File,
189193
password: None,
190194
user: None,

0 commit comments

Comments
 (0)