summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2015-10-21 16:13:35 +1300
committerRobert Ancell <robert.ancell@canonical.com>2015-10-21 16:13:35 +1300
commit32465374e79a49a6923cbbb9623505441f4fa360 (patch)
tree4072d4c03a499ca737e2522cbd2087b144976142
parent9d66897a3b0292ed42a4c5b65a988c73ad13ce48 (diff)
downloadlightdm-git-32465374e79a49a6923cbbb9623505441f4fa360.tar.gz
Handle trailing whitespace on boolean values
-rw-r--r--src/configuration.c19
-rw-r--r--src/seat.c14
2 files changed, 31 insertions, 2 deletions
diff --git a/src/configuration.c b/src/configuration.c
index 52be58d0..431fc758 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -9,6 +9,8 @@
* license.
*/
+#include <string.h>
+
#include "configuration.h"
struct ConfigurationPrivate
@@ -121,7 +123,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
diff --git a/src/seat.c b/src/seat.c
index ca255167..9e055c19 100644
--- a/src/seat.c
+++ b/src/seat.c
@@ -115,7 +115,19 @@ seat_get_string_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