Skip to content

Commit 33d9270

Browse files
authored
Merge pull request #14191 from NixOS/fix-14188
libutil: Fix renderAuthorityAndPath unreachable for path:/ URLs
2 parents d591f17 + 1d8dd77 commit 33d9270

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/libutil-tests/url.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,12 @@ TEST_P(ParsedURLPathSegmentsTest, segmentsAreCorrect)
868868
EXPECT_EQ(encodeUrlPath(segments), testCase.path);
869869
}
870870

871+
TEST_P(ParsedURLPathSegmentsTest, to_string)
872+
{
873+
const auto & testCase = GetParam();
874+
EXPECT_EQ(testCase.url, parseURL(testCase.url).to_string());
875+
}
876+
871877
INSTANTIATE_TEST_SUITE_P(
872878
ParsedURL,
873879
ParsedURLPathSegmentsTest,
@@ -886,6 +892,13 @@ INSTANTIATE_TEST_SUITE_P(
886892
.skipEmpty = false,
887893
.description = "empty_authority_empty_path",
888894
},
895+
ParsedURLPathSegmentsTestCase{
896+
.url = "path:/",
897+
.segments = {"", ""},
898+
.path = "/",
899+
.skipEmpty = false,
900+
.description = "empty_authority_root_path",
901+
},
889902
ParsedURLPathSegmentsTestCase{
890903
.url = "scheme:///",
891904
.segments = {"", ""},

src/libutil/url.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ std::string ParsedURL::renderAuthorityAndPath() const
350350
must either be empty or begin with a slash ("/") character. */
351351
assert(path.empty() || path.front().empty());
352352
res += authority->to_string();
353-
} else if (std::ranges::equal(std::views::take(path, 2), std::views::repeat("", 2))) {
353+
} else if (std::ranges::equal(std::views::take(path, 3), std::views::repeat("", 3))) {
354354
/* If a URI does not contain an authority component, then the path cannot begin
355355
with two slash characters ("//") */
356356
unreachable();

0 commit comments

Comments
 (0)