From da965109edfc988262d962bca2b9d6a6e80ecad5 Mon Sep 17 00:00:00 2001 From: Valentin Batz Date: Tue, 25 Jul 2006 11:02:10 +0000 Subject: [PATCH] Don't assume that 7bit ascii strings are encoded in UTF-8, only validate the strings when they contain octest with highest bit set. (patch by Mikko Rauhala) fixes http://bugs.irssi.org/index.php?do=details&id=392 git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4300 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/recode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/recode.c b/src/core/recode.c index 75a1c127..5bf05f9d 100644 --- a/src/core/recode.c +++ b/src/core/recode.c @@ -80,6 +80,7 @@ char *recode_in(const SERVER_REC *server, const char *str, const char *target) char *tagtarget = NULL; gboolean term_is_utf8, str_is_utf8, translit, recode, autodetect; int len; + int i; if (!str) return NULL; @@ -90,7 +91,14 @@ char *recode_in(const SERVER_REC *server, const char *str, const char *target) len = strlen(str); - str_is_utf8 = g_utf8_validate(str, len, NULL); + /* Only validate for UTF-8 if an 8-bit encoding. */ + str_is_utf8 = 0; + for (i = 0; i < len; ++i) { + if (str[i] & 0x80) { + str_is_utf8 = g_utf8_validate(str, len, NULL); + break; + } + } translit = settings_get_bool("recode_transliterate"); autodetect = settings_get_bool("recode_autodetect_utf8"); term_is_utf8 = recode_get_charset(&to);