From e050eebb2e935e69226863a2a6877fa0e63f6cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 1 Mar 2025 16:43:00 +0100 Subject: [PATCH] api: return input string in function string_iconv_from_internal when current locale is wrong This fixes a bug when writing configuration files with a wrong locale: now UTF-8 is kept and written in files instead of string converted using a wrong charset. --- CHANGELOG.md | 6 ++++++ src/core/core-string.c | 7 ++++++- src/core/weechat.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be5702714..5ce837317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # WeeChat ChangeLog +## Version 4.5.3 (under dev) + +### Fixed + +- core: save configuration files as UTF-8 when the locale is wrong + ## Version 4.5.2 (2025-02-20) ### Fixed diff --git a/src/core/core-string.c b/src/core/core-string.c index dbf22c208..a2f3134b9 100644 --- a/src/core/core-string.c +++ b/src/core/core-string.c @@ -3253,7 +3253,8 @@ string_iconv_to_internal (const char *charset, const char *string) } /* - * Converts internal string to terminal charset, for display. + * Converts internal string to terminal charset, for display or write of + * configuration files. * * Note: result must be freed after use. */ @@ -3270,6 +3271,10 @@ string_iconv_from_internal (const char *charset, const char *string) if (!input) return NULL; + /* if the locale is wrong, we keep UTF-8 */ + if (!weechat_locale_ok) + return input; + /* * optimized for UTF-8: if charset is NULL => we use term charset => if * this charset is already UTF-8, then no iconv is needed diff --git a/src/core/weechat.h b/src/core/weechat.h index 0e35487ec..461e221ae 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -118,6 +118,7 @@ extern char *weechat_data_dir; extern char *weechat_state_dir; extern char *weechat_cache_dir; extern char *weechat_runtime_dir; +extern int weechat_locale_ok; extern char *weechat_local_charset; extern int weechat_plugin_no_dlclose; extern int weechat_no_gnutls;