Skip to content

Commit

Permalink
Fix #1973
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Nov 14, 2024
1 parent 924f214 commit 95fb89e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
11 changes: 9 additions & 2 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions test/www/日本語Dir/日本語File.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
日本語コンテンツ

0 comments on commit 95fb89e

Please sign in to comment.