Skip to content

Commit 95fb89e

Browse files
committed
Fix #1973
1 parent 924f214 commit 95fb89e

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

httplib.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,8 +2910,15 @@ inline bool mmap::open(const char *path) {
29102910

29112911
#if defined(_WIN32)
29122912
std::wstring wpath;
2913-
for (size_t i = 0; i < strlen(path); i++) {
2914-
wpath += path[i];
2913+
{
2914+
auto len = static_cast<int>(strlen(path));
2915+
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, nullptr, 0);
2916+
if (wlen <= 0) { return false; }
2917+
2918+
wpath.resize(wlen);
2919+
auto pwpath = const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(wpath.data()));
2920+
wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, pwpath, wlen);
2921+
if (wlen != wpath.size()) { return false; }
29152922
}
29162923

29172924
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8

test/test.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5271,6 +5271,27 @@ TEST(MountTest, Redicect) {
52715271
EXPECT_EQ(StatusCode::OK_200, res->status);
52725272
}
52735273

5274+
TEST(MountTest, MultibytesPathName) {
5275+
Server svr;
5276+
5277+
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
5278+
auto se = detail::scope_exit([&] {
5279+
svr.stop();
5280+
listen_thread.join();
5281+
ASSERT_FALSE(svr.is_running());
5282+
});
5283+
5284+
svr.set_mount_point("/", "./www");
5285+
svr.wait_until_ready();
5286+
5287+
Client cli("localhost", PORT);
5288+
5289+
auto res = cli.Get("/日本語Dir/日本語File.txt");
5290+
ASSERT_TRUE(res);
5291+
EXPECT_EQ(StatusCode::OK_200, res->status);
5292+
EXPECT_EQ("日本語コンテンツ", res->body);
5293+
}
5294+
52745295
TEST(KeepAliveTest, ReadTimeout) {
52755296
Server svr;
52765297

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
日本語コンテンツ

0 commit comments

Comments
 (0)