This commit is contained in:
yhirose 2024-11-13 19:32:56 -05:00
parent 924f214303
commit 95fb89eb30
3 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -0,0 +1 @@
日本語コンテンツ