From 560126bffc34e1d3825c7d66d8dccc4d91b5ad75 Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 16 Oct 2026 23:52:15 -0400 Subject: [PATCH] Accept a Unix socket path with "//" in it Client took any string with "//" in it that it could not use as a URL for a bad URL, so a Unix socket path such as /run/app//api.sock gave an invalid client. Only a string that starts with a scheme and "://", or with "//", is taken for a URL now. --- httplib.h | 6 ++++-- test/test.cc | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/httplib.h b/httplib.h index c447f301..4fcef232 100644 --- a/httplib.h +++ b/httplib.h @@ -17988,8 +17988,10 @@ inline Client::Client(const std::string &scheme_host_port, cli_ = detail::make_unique(host, port, client_cert_path, client_key_path); } - } else if (scheme_host_port.find("//") != std::string::npos) { - // A URL, but not one this client can use, such as one with userinfo + } else if (scheme_host_port.compare(0, 2, "//") == 0 || + scheme_host_port.find("://") < scheme_host_port.find('/')) { + // A URL, but not one this client can use, such as one with userinfo. A + // Unix socket path may have "//" further on. cli_ = detail::make_unique(); } else { // NOTE: Update TEST(UniversalClientImplTest, Ipv6LiteralAddress) diff --git a/test/test.cc b/test/test.cc index 7f6315a4..9609d897 100644 --- a/test/test.cc +++ b/test/test.cc @@ -173,6 +173,8 @@ TEST_F(UnixSocketTest, pathname) { ASSERT_TRUE(svr.is_running()); client_GET(pathname_); + // ".//x.sock", which is not taken for a URL + client_GET("./" + pathname_.substr(1)); } #if defined(__linux__) || \ @@ -15633,6 +15635,8 @@ TEST(HostAndPortPropertiesTest, UserinfoIsNotSupported) { httplib::Client cli("http://user:pass@localhost:1234"); ASSERT_FALSE(cli.is_valid()); EXPECT_FALSE(cli.Get("/")); + + EXPECT_FALSE(httplib::Client("//user@localhost:1234").is_valid()); } TEST(HostAndPortPropertiesTest, TrailingCharactersInPort) {