2cc19f841df2

Die if there are any newlines inside the task text

The `t` file format is line-based, so newlines break the file format.  We'd have
to escape them or something, but that opens a whole can of worms, and `t` is
supposed to be simple, so we'll just forbid them.

Fixes https://github.com/sjl/t/issues/26
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 11 Apr 2020 11:23:45 -0400
parents 452a9a9cba0a
children d76f573934d1
branches/tags (none)
files t.py

Changes

--- a/t.py	Tue Jan 14 20:04:07 2020 -0500
+++ b/t.py	Sat Apr 11 11:23:45 2020 -0400
@@ -252,6 +252,10 @@
                 os.remove(path)
 
 
+def _die(message):
+    sys.stderr.write('error: %s\n' % message)
+    sys.exit(1)
+
 def _build_parser():
     """Return a parser for the command-line interface."""
     usage = "Usage: %prog [-t DIR] [-l LIST] [options] [TEXT]"
@@ -300,6 +304,9 @@
     td = TaskDict(taskdir=options.taskdir, name=options.name)
     text = ' '.join(args).strip()
 
+    if '\n' in text:
+        _die('task text cannot contain newlines')
+
     try:
         if options.finish:
             td.finish_task(options.finish)
@@ -319,12 +326,12 @@
                           grep=options.grep)
     except AmbiguousPrefix:
         e = sys.exc_info()[1]
-        sys.stderr.write('The ID "%s" matches more than one task.\n' % e.prefix)
+        _die('the ID "%s" matches more than one task' % e.prefix)
     except UnknownPrefix:
         e = sys.exc_info()[1]
-        sys.stderr.write('The ID "%s" does not match any task.\n' % e.prefix)
+        _die('the ID "%s" does not match any task' % e.prefix)
     except BadFile as e:
-        sys.stderr.write('%s - %s\n' % (e.problem, e.path))
+        _die('%s - %s' % (e.problem, e.path))
 
 
 if __name__ == '__main__':