From 07f1fc60dac480d3e4ca8e98ec1c0e08c050676d Mon Sep 17 00:00:00 2001 From: Joseph Bisch Date: Mon, 2 Oct 2017 15:11:42 -0400 Subject: Use g_utf8_make_valid if available for cleaner utf8 handling (#2065) --- src/common/server.c | 5 ++++- src/common/text.c | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/server.c b/src/common/server.c index 1ed90d0b..c0fb36a6 100644 --- a/src/common/server.c +++ b/src/common/server.c @@ -258,7 +258,10 @@ static void server_inline (server *serv, char *line, gssize len) { gsize len_utf8; - line = text_convert_invalid (line, len, serv->read_converter, unicode_fallback_string, &len_utf8); + if (!strcmp (serv->encoding, "UTF-8")) + line = text_fixup_invalid_utf8 (line, len, &len_utf8); + else + line = text_convert_invalid (line, len, serv->read_converter, unicode_fallback_string, &len_utf8); fe_add_rawlog (serv, line, len_utf8, FALSE); diff --git a/src/common/text.c b/src/common/text.c index 2677ebc4..4a274f98 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -814,6 +814,16 @@ text_convert_invalid (const gchar* text, gssize len, GIConv converter, const gch gchar * text_fixup_invalid_utf8 (const gchar* text, gssize len, gsize *len_out) { +#if GLIB_CHECK_VERSION (2, 52, 0) +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + gchar *result = g_utf8_make_valid (text, len); +G_GNUC_END_IGNORE_DEPRECATIONS + if (len_out) + { + *len_out = strlen (result); + } + return result; +#else static GIConv utf8_fixup_converter = NULL; if (utf8_fixup_converter == NULL) { @@ -821,6 +831,7 @@ text_fixup_invalid_utf8 (const gchar* text, gssize len, gsize *len_out) } return text_convert_invalid (text, len, utf8_fixup_converter, unicode_fallback_string, len_out); +#endif } void -- cgit 1.4.1