Skip to content

Commit 2afad16

Browse files
committed
remove!: url parsing error NotALocalFile
The `NotALocalFile` error variant was previously returned if the input url contained a colon but the slice after that character contained no slash character (`/` or `\`). This behavior is wrong. SCP like URLs may not need a slash character to specify the repositories location. Similarly, a local directory that contains a colon in its name is a valid repository path as well. The new implementation correctly parses such URLs.
1 parent 1a52d60 commit 2afad16

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

gix-url/src/parse/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ pub enum Error {
1111
Url(#[from] url::ParseError),
1212
#[error("file URLs require an absolute or relative path to the repository")]
1313
MissingRepositoryPath,
14-
#[error("\"{url}\" is not a valid local path")]
15-
NotALocalFile { url: BString },
1614
#[error("Relative URLs are not permitted: {url:?}")]
1715
RelativeUrl { url: String },
1816
}

gix-url/tests/parse/file.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ fn url_from_absolute_path() -> crate::Result {
142142
Ok(())
143143
}
144144

145+
#[test]
146+
fn url_from_relative_path_with_colon_in_name() -> crate::Result {
147+
let url = assert_url(
148+
"./weird/directory/na:me",
149+
url_alternate(Scheme::File, None, None, None, b"./weird/directory/na:me"),
150+
)?
151+
.to_bstring();
152+
assert_eq!(url, "./weird/directory/na:me");
153+
Ok(())
154+
}
155+
145156
mod windows {
146157
use gix_url::Scheme;
147158

gix-url/tests/parse/invalid.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,3 @@ fn empty() {
4141
fn missing_port_despite_indication() {
4242
assert_failure("ssh://host.xz:", Error::MissingRepositoryPath)
4343
}
44-
45-
#[test]
46-
fn strange() {
47-
assert_failure("file:..", "\"file:..\" is not a valid local path")
48-
}

gix-url/tests/parse/ssh.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,13 @@ fn strange_windows_paths_yield_meaningful_results() -> crate::Result {
177177
assert_eq!(url, "[email protected]:42:C:/strange/absolute/path");
178178
Ok(())
179179
}
180+
181+
// Git does not care that the host is named `file`, it still treats it as an SCP url.
182+
// I btw tested this, yes you can really clone a repository from there, just `git init`
183+
// in the directory above your home directory on the remote machine.
184+
#[test]
185+
fn strange() -> crate::Result {
186+
let url = assert_url("file:..", url_alternate(Scheme::Ssh, None, "file", None, b".."))?.to_bstring();
187+
assert_eq!(url, "file:..");
188+
Ok(())
189+
}

0 commit comments

Comments
 (0)