1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14197 from NixOS/backport-14191-to-2.32-maintenance

[Backport 2.32-maintenance] libutil: Fix renderAuthorityAndPath unreachable for path:/ URLs
This commit is contained in:
internal-nix-ci[bot] 2025-10-09 00:00:28 +00:00 committed by GitHub
commit 6b16af8c0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -868,6 +868,12 @@ TEST_P(ParsedURLPathSegmentsTest, segmentsAreCorrect)
EXPECT_EQ(encodeUrlPath(segments), testCase.path); EXPECT_EQ(encodeUrlPath(segments), testCase.path);
} }
TEST_P(ParsedURLPathSegmentsTest, to_string)
{
const auto & testCase = GetParam();
EXPECT_EQ(testCase.url, parseURL(testCase.url).to_string());
}
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ParsedURL, ParsedURL,
ParsedURLPathSegmentsTest, ParsedURLPathSegmentsTest,
@ -886,6 +892,13 @@ INSTANTIATE_TEST_SUITE_P(
.skipEmpty = false, .skipEmpty = false,
.description = "empty_authority_empty_path", .description = "empty_authority_empty_path",
}, },
ParsedURLPathSegmentsTestCase{
.url = "path:/",
.segments = {"", ""},
.path = "/",
.skipEmpty = false,
.description = "empty_authority_root_path",
},
ParsedURLPathSegmentsTestCase{ ParsedURLPathSegmentsTestCase{
.url = "scheme:///", .url = "scheme:///",
.segments = {"", ""}, .segments = {"", ""},

View file

@ -350,7 +350,7 @@ std::string ParsedURL::renderAuthorityAndPath() const
must either be empty or begin with a slash ("/") character. */ must either be empty or begin with a slash ("/") character. */
assert(path.empty() || path.front().empty()); assert(path.empty() || path.front().empty());
res += authority->to_string(); res += authority->to_string();
} else if (std::ranges::equal(std::views::take(path, 2), std::views::repeat("", 2))) { } else if (std::ranges::equal(std::views::take(path, 3), std::views::repeat("", 3))) {
/* If a URI does not contain an authority component, then the path cannot begin /* If a URI does not contain an authority component, then the path cannot begin
with two slash characters ("//") */ with two slash characters ("//") */
unreachable(); unreachable();