mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
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
47 lines
1.6 KiB
C++
47 lines
1.6 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "fetch-settings.hh"
|
|
#include "flake/flakeref.hh"
|
|
|
|
namespace nix {
|
|
|
|
/* ----------- tests for flake/flakeref.hh --------------------------------------------------*/
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
* to_string
|
|
* --------------------------------------------------------------------------*/
|
|
|
|
TEST(to_string, doesntReencodeUrl) {
|
|
fetchers::Settings fetchSettings;
|
|
auto s = "http://localhost:8181/test/+3d.tar.gz";
|
|
auto flakeref = parseFlakeRef(fetchSettings, s);
|
|
auto parsed = flakeref.to_string();
|
|
auto expected = "http://localhost:8181/test/%2B3d.tar.gz";
|
|
|
|
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);
|
|
}
|
|
}
|