]> granicus.if.org Git - neomutt/commitdiff
config: allow unset on strings
authorRichard Russon <rich@flatcap.org>
Tue, 24 Jul 2018 10:47:41 +0000 (11:47 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 24 Jul 2018 12:08:11 +0000 (13:08 +0100)
config/magic.c
config/number.c
config/sort.c
init.c

index 9947c7d617e438c39ce4ff5ceb408bfda3eb174b..584dca2f82d87655ab39454d31ca256ce77fdad6 100644 (file)
@@ -58,9 +58,15 @@ const char *magic_values[] = {
 static int magic_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef,
                             const char *value, struct Buffer *err)
 {
-  if (!cs || !cdef || !value)
+  if (!cs || !cdef)
     return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
 
+  if (!value || !value[0])
+  {
+    mutt_buffer_printf(err, "Option %s may not be empty", cdef->name);
+    return (CSR_ERR_INVALID | CSR_INV_TYPE);
+  }
+
   int num = -1;
   for (size_t i = 1; magic_values[i]; i++)
   {
index 227def2c48e1869bbbe6948051dc7309bb9ab343..f77dd918b730ac176541bfbbb91661ff864cb836 100644 (file)
@@ -52,10 +52,16 @@ static int number_string_set(const struct ConfigSet *cs, void *var, struct Confi
   if (!cs || !cdef)
     return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
 
+  if (!value || !value[0])
+  {
+    mutt_buffer_printf(err, "Option %s may not be empty", cdef->name);
+    return (CSR_ERR_INVALID | CSR_INV_TYPE);
+  }
+
   int num = 0;
-  if (!value || !value[0] || (mutt_str_atoi(value, &num) < 0))
+  if (mutt_str_atoi(value, &num) < 0)
   {
-    mutt_buffer_printf(err, "Invalid number: %s", value);
+    mutt_buffer_printf(err, "Invalid number: %s", NONULL(value));
     return (CSR_ERR_INVALID | CSR_INV_TYPE);
   }
 
index b16d9d4bde05cf4a906e1e9f7b0226b4da740cf8..b81d351ded62eb7de1011ef559185200b4f216b9 100644 (file)
@@ -145,12 +145,18 @@ const struct Mapping SortSidebarMethods[] = {
 static int sort_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef,
                            const char *value, struct Buffer *err)
 {
-  if (!cs || !cdef || !value)
+  if (!cs || !cdef)
     return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
 
   intptr_t id = -1;
   int flags = 0;
 
+  if (!value || !value[0])
+  {
+    mutt_buffer_printf(err, "Option %s may not be empty", cdef->name);
+    return (CSR_ERR_INVALID | CSR_INV_TYPE);
+  }
+
   if (mutt_str_strncmp("reverse-", value, 8) == 0)
   {
     flags |= SORT_REVERSE;
diff --git a/init.c b/init.c
index 9165780ecc84618c4030aad607707dc19360c129..c8bf26002ff55120d46baa9af23b01fe47bb73e0 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1652,14 +1652,18 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
       s->dptr++;
     }
 
-    if (!bq && (inv || unset))
+    if (!bq && (inv || (unset && prefix)))
     {
       if (data == MUTT_SET_SET)
+      {
         mutt_buffer_printf(err, "ERR06 prefixes 'no' and 'inv' may only be "
                                 "used with bool/quad variables");
+      }
       else
+      {
         mutt_buffer_printf(err, "ERR07 command '%s' can only be used with bool/quad variables",
                            set_commands[data]);
+      }
       return -1;
     }
 
@@ -1737,7 +1741,7 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
             size_t scratchlen = mutt_str_strlen(scratch);
             if (scratchlen != 0)
             {
-              if ((scratch[scratchlen - 1] != '|') &&       /* not a command */
+              if ((scratch[scratchlen - 1] != '|') && /* not a command */
                   (url_check_scheme(scratch) == U_UNKNOWN)) /* probably a local file */
               {
                 struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
@@ -1747,7 +1751,6 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
                 }
               }
             }
-
           }
           rc = cs_he_string_set(Config, he, buf->data, err);
           if (CSR_RESULT(rc) != CSR_SUCCESS)
@@ -1801,7 +1804,11 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
       }
     }
 
-    if (bq)
+    if (my)
+    {
+      myvar_del(buf->data);
+    }
+    else if (bq)
     {
       if (inv)
       {
@@ -1818,6 +1825,13 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
         if (CSR_RESULT(rc) != CSR_SUCCESS)
           return -1;
       }
+      continue;
+    }
+    else
+    {
+      rc = cs_str_string_set(Config, buf->data, NULL, err);
+      if (CSR_RESULT(rc) != CSR_SUCCESS)
+        return -1;
     }
   }