]> git.notmuchmail.org Git - notmuch/commitdiff
tag: Disallow adding malformed tags to messages
authorAustin Clements <amdragon@MIT.EDU>
Fri, 26 Oct 2012 20:54:12 +0000 (16:54 -0400)
committerDavid Bremner <bremner@debian.org>
Sat, 27 Oct 2012 12:32:44 +0000 (09:32 -0300)
This disallows adding empty tags, since nothing but confusion follows
in their wake, and disallows adding tags that begin with "-" because
they are also confusing, the tag "-" is impossible to remove using the
CLI, and because the syntax for removing such tags conflicts with long
argument syntax.

This does not place any restrictions on what tags can be removed, as
that would make it difficult for people who have the misfortune of
already having malformed tags to remove these tags.

notmuch-tag.c
test/tagging

index 7d186399ba786149d607ca2b45837836a43af802..d15f1eda481fe0a6931afbb61de38289249642db 100644 (file)
@@ -203,6 +203,17 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
            break;
        }
        if (argv[i][0] == '+' || argv[i][0] == '-') {
+           if (argv[i][0] == '+' && argv[i][1] == '\0') {
+               fprintf(stderr, "Error: tag names cannot be empty.\n");
+               return 1;
+           }
+           if (argv[i][0] == '+' && argv[i][1] == '-') {
+               /* This disallows adding the non-removable tag "-" and
+                * enables notmuch tag to take long options in the
+                * future. */
+               fprintf(stderr, "Error: tag names must not start with '-'.\n");
+               return 1;
+           }
            tag_ops[tag_ops_count].tag = argv[i] + 1;
            tag_ops[tag_ops_count].remove = (argv[i][0] == '-');
            tag_ops_count++;
index e4782ed490d70c536a6c4bfdf94397416fffaf77..980ff9274b8228bd2c2559a756cafe1ec1fefaac 100755 (executable)
@@ -46,4 +46,8 @@ test_expect_equal "$output" "\
 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)
 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag4 unread)"
 
+test_expect_code 1 "Empty tag names" 'notmuch tag + One'
+
+test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One'
+
 test_done