Skip to content

Commit 7604602

Browse files
committed
Fixed problems with 'Language for non-Unicode programs' setting on Windows
1 parent 95fb89e commit 7604602

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

httplib.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -2911,13 +2911,15 @@ inline bool mmap::open(const char *path) {
29112911
#if defined(_WIN32)
29122912
std::wstring wpath;
29132913
{
2914+
auto cp = ::GetACP();
2915+
29142916
auto len = static_cast<int>(strlen(path));
2915-
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, nullptr, 0);
2917+
auto wlen = ::MultiByteToWideChar(cp, 0, path, len, nullptr, 0);
29162918
if (wlen <= 0) { return false; }
29172919

29182920
wpath.resize(wlen);
29192921
auto pwpath = const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(wpath.data()));
2920-
wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, pwpath, wlen);
2922+
wlen = ::MultiByteToWideChar(cp, 0, path, len, pwpath, wlen);
29212923
if (wlen != wpath.size()) { return false; }
29222924
}
29232925

test/test.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// NOTE: This file should be saved as UTF-8 w/ BOM
12
#include <httplib.h>
23
#include <signal.h>
34

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

247248
TEST(DecodeURLTest, PercentCharacterNUL) {
@@ -267,9 +268,9 @@ TEST(EncodeQueryParamTest, ParseReservedCharactersTest) {
267268
}
268269

269270
TEST(EncodeQueryParamTest, TestUTF8Characters) {
270-
string chineseCharacters = "中国語";
271-
string russianCharacters = "дом";
272-
string brazilianCharacters = "óculos";
271+
string chineseCharacters = u8"中国語";
272+
string russianCharacters = u8"дом";
273+
string brazilianCharacters = u8"óculos";
273274

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

52955296
TEST(KeepAliveTest, ReadTimeout) {

0 commit comments

Comments
 (0)