mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 20:16:03 +01:00
Handle empty ports
This commit is contained in:
parent
1e16a54ee5
commit
7989e3192d
2 changed files with 18 additions and 1 deletions
|
|
@ -273,6 +273,23 @@ TEST(parseURL, emptyStringIsInvalidURL)
|
||||||
ASSERT_THROW(parseURL(""), Error);
|
ASSERT_THROW(parseURL(""), Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(parseURL, parsesHttpUrlWithEmptyPort)
|
||||||
|
{
|
||||||
|
auto s = "http://www.example.org:/file.tar.gz?foo=bar";
|
||||||
|
auto parsed = parseURL(s);
|
||||||
|
|
||||||
|
ParsedURL expected{
|
||||||
|
.scheme = "http",
|
||||||
|
.authority = Authority{.hostType = HostType::Name, .host = "www.example.org"},
|
||||||
|
.path = "/file.tar.gz",
|
||||||
|
.query = (StringMap) {{"foo", "bar"}},
|
||||||
|
.fragment = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
ASSERT_EQ(parsed, expected);
|
||||||
|
ASSERT_EQ("http://www.example.org/file.tar.gz?foo=bar", parsed.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* decodeQuery
|
* decodeQuery
|
||||||
* --------------------------------------------------------------------------*/
|
* --------------------------------------------------------------------------*/
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ ParsedURL::Authority ParsedURL::Authority::parse(std::string_view encodedAuthori
|
||||||
}();
|
}();
|
||||||
|
|
||||||
auto port = [&]() -> std::optional<uint16_t> {
|
auto port = [&]() -> std::optional<uint16_t> {
|
||||||
if (!parsed->has_port())
|
if (!parsed->has_port() || parsed->port() == "")
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
/* If the port number is non-zero and representable. */
|
/* If the port number is non-zero and representable. */
|
||||||
if (auto portNumber = parsed->port_number())
|
if (auto portNumber = parsed->port_number())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue