From 7f4d8491f32a0bb8ea37376443429e162ea6cd86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Mon, 23 Jan 2017 09:18:53 +0100 Subject: prefs: Preserve UTF-8 characters in preferences. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When saving preferences the strings in string lists must not be escaped with g_strescape() because this will destroy UTF-8 characters. Because this strings only should use printable characters we manually escape quote and backslash, and skip non-printable. Bug: 13342 Change-Id: I57e492dff746a5ecc0aee809f946a615ad110b4d Reviewed-on: https://code.wireshark.org/review/19738 Petri-Dish: Stig Bjørlykke Reviewed-by: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/prefs.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/epan/prefs.c b/epan/prefs.c index b1528d7cf8..d834601a6a 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -3649,7 +3649,6 @@ char *join_string_list(GList *sl) GString *joined_str = g_string_new(""); GList *cur, *first; gchar *str; - gchar *quoted_str; guint item_count = 0; cur = first = g_list_first(sl); @@ -3666,9 +3665,20 @@ char *join_string_list(GList *sl) } else g_string_append_c(joined_str, ' '); - quoted_str = g_strescape(str, ""); - g_string_append_printf(joined_str, "\"%s\"", quoted_str); - g_free(quoted_str); + g_string_append_c(joined_str, '"'); + while (*str) { + gunichar uc = g_utf8_get_char (str); + + if (uc == '"' || uc == '\\') + g_string_append_c(joined_str, '\\'); + + if (g_unichar_isprint(uc)) + g_string_append_unichar (joined_str, uc); + + str = g_utf8_next_char (str); + } + + g_string_append_c(joined_str, '"'); cur = cur->next; } -- cgit v1.2.1