mirror of
https://github.com/NixOS/nix
synced 2025-07-04 23:51:47 +02:00
Exclude 'dir' from the FlakeRef's URL
This fixes an issue where nix would try to check out invalid URLs,
because it would pass 'dir' to the HTTP endpoint.
For later versions this was fixed in
b2be6fed86
. This is a backport of just the
relevant part.
See #12417
This commit is contained in:
parent
57190f9a39
commit
72bf563191
2 changed files with 27 additions and 3 deletions
|
@ -234,15 +234,16 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto subdir = getOr(parsedURL.query, "dir", "");
|
||||||
|
parsedURL.query.erase("dir");
|
||||||
|
|
||||||
std::string fragment;
|
std::string fragment;
|
||||||
std::swap(fragment, parsedURL.fragment);
|
std::swap(fragment, parsedURL.fragment);
|
||||||
|
|
||||||
auto input = fetchers::Input::fromURL(fetchSettings, parsedURL, isFlake);
|
auto input = fetchers::Input::fromURL(fetchSettings, parsedURL, isFlake);
|
||||||
input.parent = baseDir;
|
input.parent = baseDir;
|
||||||
|
|
||||||
return std::make_pair(
|
return std::make_pair(FlakeRef(std::move(input), subdir), fragment);
|
||||||
FlakeRef(std::move(input), getOr(parsedURL.query, "dir", "")),
|
|
||||||
fragment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
||||||
|
|
|
@ -21,4 +21,27 @@ namespace nix {
|
||||||
ASSERT_EQ(parsed, expected);
|
ASSERT_EQ(parsed, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* parseFlakeRef
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
TEST(parseFlakeRef, removesDirFromInputURL) {
|
||||||
|
fetchers::Settings fetchSettings;
|
||||||
|
auto s = "git+https://localhost:8181/test/test.git?dir=subdir";
|
||||||
|
auto flakeref = parseFlakeRef(fetchSettings, s);
|
||||||
|
auto expected = "git+https://localhost:8181/test/test.git";
|
||||||
|
auto inputURL = flakeref.input.toURLString();
|
||||||
|
|
||||||
|
ASSERT_EQ(inputURL, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(parseFlakeRef, setsSubdir) {
|
||||||
|
fetchers::Settings fetchSettings;
|
||||||
|
auto s = "git+https://localhost:8181/test/test.git?dir=subdir";
|
||||||
|
auto flakeref = parseFlakeRef(fetchSettings, s);
|
||||||
|
auto expected = "subdir";
|
||||||
|
auto flakerefSubdir = flakeref.subdir;
|
||||||
|
|
||||||
|
ASSERT_EQ(flakerefSubdir, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue