# HG changeset patch # User Steve Losh # Date 1586618625 14400 # Node ID 2cc19f841df2614f9321e3b8c854dee1ea241d61 # Parent 452a9a9cba0a25a7dc35447fa4ab10d1ed21b9ab 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 diff -r 452a9a9cba0a -r 2cc19f841df2 t.py --- 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__':