mhabrnal / rpms / gdm

Forked from rpms/gdm 6 years ago
Clone
Blob Blame History Raw
diff -up gdm-2.20.5/common/gdm-common.c.fix-non-utf8 gdm-2.20.5/common/gdm-common.c
--- gdm-2.20.5/common/gdm-common.c.fix-non-utf8	2008-06-23 20:25:29.000000000 -0400
+++ gdm-2.20.5/common/gdm-common.c	2008-06-23 20:27:53.000000000 -0400
@@ -211,6 +211,26 @@ ve_get_first_working_command (const char
 	return ret;
 }
 
+static char *
+get_valid_utf8 (const char *text)
+{
+	gchar *utf8_string, *escaped_string, *p;
+	const gchar *q;
+ 
+	utf8_string = g_strdup (text);
+	p = utf8_string;
+	while ((*p != '\0') && 
+	       !g_utf8_validate (p, -1, &q)) {
+		p = (gchar *) q;
+		*p = '?';
+		p++;
+	}
+ 
+	g_assert (g_utf8_validate (utf8_string, -1, NULL));
+ 
+	return utf8_string;
+}
+
 char *
 ve_locale_to_utf8 (const char *str)
 {
@@ -218,7 +238,7 @@ ve_locale_to_utf8 (const char *str)
 
 	if (ret == NULL) {
 		g_warning ("string not in proper locale encoding: \"%s\"", str);
-		return g_strdup (str);
+		return get_valid_utf8 (str);
 	} else {
 		return ret;
 	}