diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2015-10-21 16:09:13 +1300 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2015-10-21 16:09:13 +1300 |
commit | 3d5069a8067cacf7b5179bbb4b8cda7f7fa5cdc2 (patch) | |
tree | 3e0286e068b689dc47736882f6d76417f172a2ac | |
parent | 28844815803d08937c1c9b74ed025ae803372cb0 (diff) | |
download | lightdm-git-3d5069a8067cacf7b5179bbb4b8cda7f7fa5cdc2.tar.gz |
Handle trailing whitespace on boolean values
-rw-r--r-- | common/configuration.c | 17 | ||||
-rw-r--r-- | src/seat.c | 14 |
2 files changed, 29 insertions, 2 deletions
diff --git a/common/configuration.c b/common/configuration.c index 895085e3..2420857a 100644 --- a/common/configuration.c +++ b/common/configuration.c @@ -317,7 +317,22 @@ config_set_boolean (Configuration *config, const gchar *section, const gchar *ke gboolean config_get_boolean (Configuration *config, const gchar *section, const gchar *key) { - return g_key_file_get_boolean (config->priv->key_file, section, key, NULL); + /* We don't use the standard function because it doesn't work with trailing whitespace: + * https://bugzilla.gnome.org/show_bug.cgi?id=664740 + */ + /*return g_key_file_get_boolean (config->priv->key_file, section, key, NULL);*/ + + gchar *value; + gboolean v; + + value = g_key_file_get_value (config->priv->key_file, section, key, NULL); + if (!value) + return FALSE; + g_strchomp (value); + v = strcmp (value, "true") == 0; + g_free (value); + + return v; } static void @@ -144,7 +144,19 @@ seat_get_string_list_property (Seat *seat, const gchar *name) gboolean seat_get_boolean_property (Seat *seat, const gchar *name) { - return g_strcmp0 (seat_get_string_property (seat, name), "true") == 0; + const gchar *value; + gint i, length = 0; + + value = seat_get_string_property (seat, name); + if (!value) + return FALSE; + + /* Count the number of non-whitespace characters */ + for (i = 0; value[i]; i++) + if (!g_ascii_isspace (value[i])) + length = i + 1; + + return strncmp (value, "true", MAX (length, 4)) == 0; } gint |