Skip to content

Commit

Permalink
Fixed problems with 'Language for non-Unicode programs' setting on Wi…
Browse files Browse the repository at this point in the history
…ndows
  • Loading branch information
yhirose committed Nov 14, 2024
1 parent 95fb89e commit 7604602
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2911,13 +2911,15 @@ inline bool mmap::open(const char *path) {
#if defined(_WIN32)
std::wstring wpath;
{
auto cp = ::GetACP();

auto len = static_cast<int>(strlen(path));
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, nullptr, 0);
auto wlen = ::MultiByteToWideChar(cp, 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);
wlen = ::MultiByteToWideChar(cp, 0, path, len, pwpath, wlen);
if (wlen != wpath.size()) { return false; }
}

Expand Down
11 changes: 6 additions & 5 deletions test/test.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// NOTE: This file should be saved as UTF-8 w/ BOM
#include <httplib.h>
#include <signal.h>

Expand Down Expand Up @@ -241,7 +242,7 @@ TEST(DecodeURLTest, PercentCharacter) {
detail::decode_url(
R"(descrip=Gastos%20%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA%C3%B1%C3%91%206)",
false),
R"(descrip=Gastos áéíóúñÑ 6)");
u8"descrip=Gastos áéíóúñÑ 6");
}

TEST(DecodeURLTest, PercentCharacterNUL) {
Expand All @@ -267,9 +268,9 @@ TEST(EncodeQueryParamTest, ParseReservedCharactersTest) {
}

TEST(EncodeQueryParamTest, TestUTF8Characters) {
string chineseCharacters = "中国語";
string russianCharacters = "дом";
string brazilianCharacters = "óculos";
string chineseCharacters = u8"中国語";
string russianCharacters = u8"дом";
string brazilianCharacters = u8"óculos";

EXPECT_EQ(detail::encode_query_param(chineseCharacters),
"%E4%B8%AD%E5%9B%BD%E8%AA%9E");
Expand Down Expand Up @@ -5289,7 +5290,7 @@ TEST(MountTest, MultibytesPathName) {
auto res = cli.Get("/日本語Dir/日本語File.txt");
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ("日本語コンテンツ", res->body);
EXPECT_EQ(u8"日本語コンテンツ", res->body);
}

TEST(KeepAliveTest, ReadTimeout) {
Expand Down

0 comments on commit 7604602

Please sign in to comment.