diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 14686ed1fd..6a7ed61f5c 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -317,6 +317,21 @@ nm_utils_ssid_to_utf8 (const guint8 *ssid, gsize len) "UTF-8", e1, "?", NULL, NULL, NULL); } + if (!converted) { + /* If there is still no converted string, the SSID probably + * contains characters not valid in the current locale. Convert + * the string to ASCII instead. + */ + + /* Use the printable range of 0x20-0x7E */ + gchar *valid_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" + "abcdefghijklmnopqrstuvwxyz{|}~"; + + converted = g_strndup ((const gchar *)ssid, len); + g_strcanon (converted, valid_chars, '?'); + } + return converted; } diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index d0c2ca31f8..143063e7f5 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -332,6 +332,21 @@ nm_utils_ssid_to_utf8 (const GByteArray *ssid) "UTF-8", e1, "?", NULL, NULL, NULL); } + if (!converted) { + /* If there is still no converted string, the SSID probably + * contains characters not valid in the current locale. Convert + * the string to ASCII instead. + */ + + /* Use the printable range of 0x20-0x7E */ + gchar *valid_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" + "abcdefghijklmnopqrstuvwxyz{|}~"; + + converted = g_strndup ((const gchar *)ssid->data, ssid->len); + g_strcanon (converted, valid_chars, '?'); + } + return converted; }