irssi-import / bugs.irssi.org

bugs.irssi.org archive
https://github.com/irssi/irssi/issues
0 stars 0 forks source link

[Patch] Strip leading and trailing whitespaces from /SET bool values #769

Closed irssibot closed 14 years ago

irssibot commented 14 years ago

Doing, for example, "/SET paste_join_multiline on " (notice the trailing whitespace) results in:

21:11.00 -!- Irssi: Value must be either ON, OFF or TOGGLE 21:11.00 [misc] 21:11.00 paste_join_multiline = OFF

This patch strips trailing (and leading) whitespaces from SET BOOL values.

irssibot commented 14 years ago

strip_leading_and_trailing_whitespaces_from_set_value.diff

Index: src/fe-common/core/fe-settings.c
===================================================================
--- src/fe-common/core/fe-settings.c    (revision 5190)
+++ src/fe-common/core/fe-settings.c    (working copy)
@@ -66,6 +66,8 @@

 static void set_boolean(const char *key, const char *value)
 {
+   value = g_strstrip(value);
+
    if (g_ascii_strcasecmp(value, "ON") == 0)
        settings_set_bool(key, TRUE);
    else if (g_ascii_strcasecmp(value, "OFF") == 0)
irssibot commented 14 years ago

The first patch is incorrect, I was not thinking straight and made a mistake. This one should be fine, though. :-) Thanks for the feedback, ahf!

irssibot commented 14 years ago

strip_leading_and_trailing_whitespaces_from_set_value.diff

Index: src/fe-common/core/fe-settings.c
===================================================================
--- src/fe-common/core/fe-settings.c    (revision 5190)
+++ src/fe-common/core/fe-settings.c    (working copy)
@@ -66,14 +66,20 @@

 static void set_boolean(const char *key, const char *value)
 {
-   if (g_ascii_strcasecmp(value, "ON") == 0)
+   char *stripped_value;
+   stripped_value = g_strdup(value);
+   g_strstrip(stripped_value);
+
+   if (g_ascii_strcasecmp(stripped_value, "ON") == 0)
        settings_set_bool(key, TRUE);
-   else if (g_ascii_strcasecmp(value, "OFF") == 0)
+   else if (g_ascii_strcasecmp(stripped_value, "OFF") == 0)
        settings_set_bool(key, FALSE);
-   else if (g_ascii_strcasecmp(value, "TOGGLE") == 0)
+   else if (g_ascii_strcasecmp(stripped_value, "TOGGLE") == 0)
        settings_set_bool(key, !settings_get_bool(key));
    else
        printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_NOT_TOGGLE);
+
+    g_free(stripped_value);
 }

 static void set_int(const char *key, const char *value)
irssibot commented 14 years ago

Commited, Thanks.