From 8f096629ec00a9b4eb8fea3a3a0e5710256bd052 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 12 Jan 2021 04:16:03 +0100 Subject: [PATCH] Unbreak tests glib already runs the argument through g_locale_to_utf8 with G_OPTION_REMAINING --- src/libwrapper.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libwrapper.cpp b/src/libwrapper.cpp index f900edc..0cd047c 100644 --- a/src/libwrapper.cpp +++ b/src/libwrapper.cpp @@ -332,10 +332,17 @@ search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool f glib::Error err; search_result rval = SEARCH_SUCCESS; glib::CharStr str; - if (!utf8_input_) - str.reset(g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, get_addr(err))); - else + // Glib already runs CLI arguments through g_locale_to_utf8 + if (g_get_charset(nullptr)) { + // Current locale is UTF-8 str.reset(g_strdup(loc_str)); + } else { + if (!utf8_input_) { + str.reset(g_strdup(loc_str)); + } else { + str.reset(g_locale_from_utf8(loc_str, -1, &bytes_read, &bytes_written, get_addr(err))); + } + } if (nullptr == get_impl(str)) { fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);