Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 679a7f4

Browse files
committed
Use same logic for file urls and local file paths
1 parent 8af79ec commit 679a7f4

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

gix-url/src/parse/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ 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),
87+
InputScheme::Url { protocol_end } if input[..protocol_end].eq_ignore_ascii_case(b"file") => {
88+
// strip the protocol part
89+
parse_local(&input[protocol_end + 3..], true)
90+
}
8691
InputScheme::Url { .. } => parse_url(input),
8792
InputScheme::Scp { colon } => parse_scp(input, colon),
88-
InputScheme::Local => parse_local(input),
8993
}
9094
}
9195

@@ -172,16 +176,18 @@ fn parse_scp(input: &BStr, colon: usize) -> Result<crate::Url, Error> {
172176
})
173177
}
174178

175-
fn parse_local(input: &BStr) -> Result<crate::Url, Error> {
179+
fn parse_local(input: &BStr, was_in_url_format: bool) -> Result<crate::Url, Error> {
176180
if input.is_empty() {
177181
return Err(Error::MissingRepositoryPath {
178182
url: input.to_owned(),
179183
kind: UrlKind::Local,
180184
});
181185
}
182186

187+
// TODO: handle relative paths, Git does weird stuff
188+
183189
Ok(crate::Url {
184-
serialize_alternative_form: true,
190+
serialize_alternative_form: !was_in_url_format,
185191
scheme: crate::scheme::Scheme::File,
186192
password: None,
187193
user: None,

0 commit comments

Comments
 (0)