From 75cd5e1f3d3e898cceda5e8fb84ca8140843258d Mon Sep 17 00:00:00 2001 From: Jon Trowbridge Date: Mon, 29 Oct 2001 21:27:25 +0000 Subject: Silently drop match strings that contain invalid utf-8... not a good thing 2001-10-29 Jon Trowbridge * gal/e-text/e-completion-match.c (e_completion_match_set_text): Silently drop match strings that contain invalid utf-8... not a good thing to do, but better than any of the currently available alternatives. svn path=/trunk/; revision=14364 --- widgets/text/e-completion-match.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'widgets/text') diff --git a/widgets/text/e-completion-match.c b/widgets/text/e-completion-match.c index a5b26e0857..e61362a561 100644 --- a/widgets/text/e-completion-match.c +++ b/widgets/text/e-completion-match.c @@ -82,43 +82,42 @@ e_completion_match_set_text (ECompletionMatch *match, const gchar *match_text, const gchar *menu_text) { - gchar *to_be_freed_match_text; - gchar *to_be_freed_menu_text; - g_return_if_fail (match != NULL); - to_be_freed_match_text = match->match_text; - to_be_freed_menu_text = match->menu_text; + /* We silently drop any entries w/ invalid utf8. + This is not optimal behavior. */ - if (match_text == NULL) { - match_text = "Unknown_Match"; - } else if (! g_utf8_validate (match_text, -1, NULL)) { - match_text = "Invalid_UTF8"; + if (match_text && ! g_utf8_validate (match_text, -1, NULL)) { + match_text = NULL; } - if (menu_text == NULL) { - menu_text = match_text; - } else if (! g_utf8_validate (menu_text, -1, NULL)) { - menu_text = "Invalid_UTF8"; + if (menu_text && ! g_utf8_validate (menu_text, -1, NULL)) { + menu_text = NULL; } + if (match->match_text && match->match_text != match_text) { + g_free (match->match_text); + } match->match_text = g_strdup (match_text); - match->menu_text = g_strdup (menu_text); - g_free (to_be_freed_match_text); - g_free (to_be_freed_menu_text); + if (match->menu_text && match->menu_text != menu_text) { + g_free (match->menu_text); + } + match->menu_text = g_strdup (menu_text); } const gchar * e_completion_match_get_match_text (ECompletionMatch *match) { - return match ? match->match_text : "NULL_Match"; + g_return_val_if_fail (match != NULL, NULL); + return match->match_text; } const gchar * e_completion_match_get_menu_text (ECompletionMatch *match) { - return match ? match->menu_text : "NULL_Match"; + g_return_val_if_fail (match != NULL, NULL); + return match->menu_text; } gint -- cgit v1.2.3