unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/1] add some constraints to tag contents
@ 2011-11-10 21:14 Jani Nikula
  2011-11-10 21:14 ` [PATCH 1/1] cli: add some constraints to tags Jani Nikula
  0 siblings, 1 reply; 2+ messages in thread
From: Jani Nikula @ 2011-11-10 21:14 UTC (permalink / raw)
  To: notmuch

Hi, spawning from the realization that tags are pretty much unconstrained in
what they can contain (newlines, whitespace, a solo '-' which you can add but
not remove, etc.) there was some talk on IRC about restricting them. Notmuch,
but a little. This patch does just that. Perhaps it should be in lib rather than
cli, but it's a start for a discussion on what's an acceptable tag really.


BR,
Jani.


Jani Nikula (1):
  cli: add some constraints to tags

 notmuch-client.h |    1 +
 notmuch-tag.c    |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

-- 
1.7.5.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] cli: add some constraints to tags
  2011-11-10 21:14 [PATCH 0/1] add some constraints to tag contents Jani Nikula
@ 2011-11-10 21:14 ` Jani Nikula
  0 siblings, 0 replies; 2+ messages in thread
From: Jani Nikula @ 2011-11-10 21:14 UTC (permalink / raw)
  To: notmuch

Forbid zero length tags, tags with leading '-', tags with leading or
trailing whitespace, and tags containing whitespace other than space ' '.

Signed-off-by: Jani Nikula <jani@nikula.org>
---
 notmuch-client.h |    1 +
 notmuch-tag.c    |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index b50cb38..ff286b0 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -46,6 +46,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <signal.h>
+#include <ctype.h>
 
 #include <talloc.h>
 
diff --git a/notmuch-tag.c b/notmuch-tag.c
index dded39e..fb7a2f3 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -30,6 +30,22 @@ handle_sigint (unused (int sig))
     interrupted = 1;
 }
 
+static int
+tag_valid(const char *tag)
+{
+    /* no zero length tag, leading whitespace or leading - */
+    if (*tag == '\0' || isspace ((unsigned char) *tag) || *tag == '-')
+	return 0;
+
+    /* no whitespace except ' ', no trailing whitespace */
+    for (tag++; *tag; tag++) {
+	if (isspace ((unsigned char) *tag) && (*tag != ' ' || *(tag+1) == '\0'))
+	    return 0;
+    }
+
+    return 1;
+}
+
 int
 notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
 {
@@ -73,6 +89,10 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
 	    break;
 	}
 	if (argv[i][0] == '+') {
+	    if (!tag_valid (argv[i] + 1)) {
+		fprintf (stderr, "Error: Invalid tag %s\n", argv[i] + 1);
+		return 1;
+	    }
 	    add_tags[add_tags_count++] = i;
 	} else if (argv[i][0] == '-') {
 	    remove_tags[remove_tags_count++] = i;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-10 21:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-10 21:14 [PATCH 0/1] add some constraints to tag contents Jani Nikula
2011-11-10 21:14 ` [PATCH 1/1] cli: add some constraints to tags Jani Nikula

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).