diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2017-01-23 09:18:53 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-01-27 05:06:39 +0000 |
commit | 7f4d8491f32a0bb8ea37376443429e162ea6cd86 (patch) | |
tree | 28d9a0625aa72f39c64ebc5cbe9c6f1d1c816a4f | |
parent | 87f4dc0a9d22060d379db2daa3f4271137a4edcc (diff) | |
download | wireshark-7f4d8491f32a0bb8ea37376443429e162ea6cd86.tar.gz |
prefs: Preserve UTF-8 characters in preferences.
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 <stig@bjorlykke.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | epan/prefs.c | 18 |
1 files 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; } |