mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-09-30 20:52:31 +07:00
Fix #2318
This commit is contained in:
@@ -2443,16 +2443,20 @@ namespace detail {
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
inline std::wstring u8string_to_wstring(const char *s) {
|
inline std::wstring u8string_to_wstring(const char *s) {
|
||||||
std::wstring ws;
|
if (!s) { return std::wstring(); }
|
||||||
|
|
||||||
auto len = static_cast<int>(strlen(s));
|
auto len = static_cast<int>(strlen(s));
|
||||||
|
if (!len) { return std::wstring(); }
|
||||||
|
|
||||||
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, s, len, nullptr, 0);
|
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, s, len, nullptr, 0);
|
||||||
if (wlen > 0) {
|
if (!wlen) { return std::wstring(); }
|
||||||
ws.resize(wlen);
|
|
||||||
wlen = ::MultiByteToWideChar(
|
std::wstring ws;
|
||||||
CP_UTF8, 0, s, len,
|
ws.resize(wlen);
|
||||||
const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(ws.data())), wlen);
|
wlen = ::MultiByteToWideChar(
|
||||||
if (wlen != static_cast<int>(ws.size())) { ws.clear(); }
|
CP_UTF8, 0, s, len,
|
||||||
}
|
const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(ws.data())), wlen);
|
||||||
|
if (wlen != static_cast<int>(ws.size())) { ws.clear(); }
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14086,3 +14086,18 @@ TEST_F(SSEIntegrationTest, LastEventIdSentOnReconnect) {
|
|||||||
EXPECT_EQ(received_last_event_ids[1], "event-0");
|
EXPECT_EQ(received_last_event_ids[1], "event-0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Issue2318Test, EmptyHostString) {
|
||||||
|
{
|
||||||
|
httplib::Client cli_empty("", PORT);
|
||||||
|
auto res = cli_empty.Get("/");
|
||||||
|
ASSERT_FALSE(res);
|
||||||
|
EXPECT_EQ(httplib::Error::Connection, res.error());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
httplib::Client cli(" ", PORT);
|
||||||
|
auto res = cli.Get("/");
|
||||||
|
ASSERT_FALSE(res);
|
||||||
|
EXPECT_EQ(httplib::Error::Connection, res.error());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user