Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set locale only once per request #430

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/cgimap/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ inline size_t unicode_strlen(const std::string & s)
{
const char* mbstr = s.c_str();

std::setlocale(LC_ALL, "C.UTF-8"); // TODO: check location for setlocale

std::mbstate_t state{};
std::size_t len = std::mbsrtowcs(nullptr, &mbstr, 0, &state);

Expand Down
3 changes: 3 additions & 0 deletions src/process_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,13 @@ void process_request(request &req, rate_limiter &limiter,
const std::string &generator, const routes &route,
data_selection::factory& factory,
data_update::factory* update_factory) {

try {

RequestContext req_ctx{req};

std::setlocale(LC_ALL, "C.UTF-8");

// get the client IP address
const auto ip = fcgi_get_env(req, "REMOTE_ADDR");

Expand Down
1 change: 1 addition & 0 deletions test/test_parse_changeset_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace {

std::map<std::string, std::string> process_testmsg(const std::string &payload) {

std::setlocale(LC_ALL, "C.UTF-8");
api06::ChangesetXMLParser parser{};
return parser.process_message(payload);
}
Expand Down
1 change: 1 addition & 0 deletions test/test_parse_osmchange_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ std::string repeat(const std::string &input, size_t num) {

void process_testmsg(const std::string &payload) {

std::setlocale(LC_ALL, "C.UTF-8");
Test_Parser_Callback cb;
api06::OSMChangeXMLParser parser(cb);
parser.process_message(payload);
Expand Down