Fix #1973
This commit is contained in:
parent
924f214303
commit
95fb89eb30
11
httplib.h
11
httplib.h
@ -2910,8 +2910,15 @@ inline bool mmap::open(const char *path) {
|
||||
|
||||
#if defined(_WIN32)
|
||||
std::wstring wpath;
|
||||
for (size_t i = 0; i < strlen(path); i++) {
|
||||
wpath += path[i];
|
||||
{
|
||||
auto len = static_cast<int>(strlen(path));
|
||||
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, nullptr, 0);
|
||||
if (wlen <= 0) { return false; }
|
||||
|
||||
wpath.resize(wlen);
|
||||
auto pwpath = const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(wpath.data()));
|
||||
wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, pwpath, wlen);
|
||||
if (wlen != wpath.size()) { return false; }
|
||||
}
|
||||
|
||||
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
|
||||
|
||||
21
test/test.cc
21
test/test.cc
@ -5271,6 +5271,27 @@ TEST(MountTest, Redicect) {
|
||||
EXPECT_EQ(StatusCode::OK_200, res->status);
|
||||
}
|
||||
|
||||
TEST(MountTest, MultibytesPathName) {
|
||||
Server svr;
|
||||
|
||||
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
|
||||
auto se = detail::scope_exit([&] {
|
||||
svr.stop();
|
||||
listen_thread.join();
|
||||
ASSERT_FALSE(svr.is_running());
|
||||
});
|
||||
|
||||
svr.set_mount_point("/", "./www");
|
||||
svr.wait_until_ready();
|
||||
|
||||
Client cli("localhost", PORT);
|
||||
|
||||
auto res = cli.Get("/日本語Dir/日本語File.txt");
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(StatusCode::OK_200, res->status);
|
||||
EXPECT_EQ("日本語コンテンツ", res->body);
|
||||
}
|
||||
|
||||
TEST(KeepAliveTest, ReadTimeout) {
|
||||
Server svr;
|
||||
|
||||
|
||||
1
test/www/日本語Dir/日本語File.txt
Normal file
1
test/www/日本語Dir/日本語File.txt
Normal file
@ -0,0 +1 @@
|
||||
日本語コンテンツ
|
||||
Loading…
Reference in New Issue
Block a user