1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-10 12:36:01 +01:00

Make fixGitURL reject file:/foo/bar/ URL

This is a breaking change, but I think a good one. If we had allowed it,
Git/SCP and the rest of our code would have disagreed on what this URL
meant.
This commit is contained in:
John Ericson 2025-09-01 16:49:18 -04:00
parent 7195250fc4
commit c80805cb61
2 changed files with 20 additions and 15 deletions

View file

@ -74,19 +74,6 @@ INSTANTIATE_TEST_SUITE_P(
.path = {"", "home", "me", "repo"},
},
},
// Already file: scheme
// NOTE: Git/SCP treat this as a `<hostname>:<path>`, so we are
// failing to "fix up" this case.
FixGitURLParam{
.input = "file:/var/repos/x",
.expected = "file:/var/repos/x",
.parsed =
ParsedURL{
.scheme = "file",
.authority = std::nullopt,
.path = {"", "var", "repos", "x"},
},
},
// IPV6 test case
FixGitURLParam{
.input = "user@[2001:db8:1::2]:/home/file",
@ -136,6 +123,17 @@ TEST(FixGitURLTestSuite, properlyRejectFileURLWithAuthority)
testing::HasSubstrIgnoreANSIMatcher("file:// URL 'file://var/repos/x' has unexpected authority 'var'")));
}
TEST(FixGitURLTestSuite, ambiguousScpLikeOrFileURL)
{
/* Git/SCP treat this as a `<hostname>:<path>`, but under IETF RFC
8089 it is a valid (if sloppy) file URL. Rather than decide who
is right, we just make it an error. */
EXPECT_THAT(
[]() { fixGitURL("file:/var/repos/x"); },
::testing::ThrowsMessage<BadURL>(testing::HasSubstrIgnoreANSIMatcher(
"URL 'file:/var/repos/x' would parse as SCP authority = 'file', path = '/var/repos/x' but this is also a valid `file:..` URL, and so we choose to disallow it")));
}
TEST(FixGitURLTestSuite, scpLikePathLeadingSlashParsesPoorly)
{
// SCP-like URL (no user)