]> arthur.barton.de Git - bup.git/commitdiff
options.py: don't crash given semi-invalid optspecs.
authorAvery Pennarun <apenwarr@gmail.com>
Mon, 19 Mar 2012 18:34:51 +0000 (14:34 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 19 Mar 2012 18:36:33 +0000 (14:36 -0400)
It's kind of weird to provide an argument without a description, but it's
not crash-worthy (especially when the crash was a totally unhelpful
exception stack trace).  While we're here, test for a couple of other ones
that didn't cause a crash, but we want to keep it that way.

And fix the copyright message; actually options.py started in 2010.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/options.py
lib/bup/t/toptions.py

index 9bcead7e19db49a3992dc251fe2ef57a30da6dbf..716ab9c93f1a3e16757238b0aa4fb1517f872b3c 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011 Avery Pennarun and options.py contributors.
+# Copyright 2010-2012 Avery Pennarun and options.py contributors.
 # All rights reserved.
 #
 # (This license applies to this file but not necessarily the other files in
@@ -169,7 +169,7 @@ class Options:
                                        l.lstrip()))
                 last_was_option = False
             elif l:
-                (flags, extra) = l.split(' ', 1)
+                (flags,extra) = (l + ' ').split(' ', 1)
                 extra = extra.strip()
                 if flags.endswith('='):
                     flags = flags[:-1]
index 7a0da0c60c32e837d4cac817071105bc6394bd63..d01227703a0d8cf3c9569657c6ced832118da2c7 100644 (file)
@@ -1,6 +1,7 @@
 from bup import options
 from wvtest import *
 
+
 @wvtest
 def test_optdict():
     d = options.OptDict()
@@ -22,6 +23,28 @@ def test_optdict():
         WVFAIL("exception expected")
 
 
+invalid_optspec0 = """
+"""
+
+
+invalid_optspec1 = """
+prog <whatever>
+"""
+
+
+invalid_optspec2 = """
+--
+x,y
+"""
+
+
+@wvtest
+def test_invalid_optspec():
+    WVPASS(options.Options(invalid_optspec0).parse([]))
+    WVPASS(options.Options(invalid_optspec1).parse([]))
+    WVPASS(options.Options(invalid_optspec2).parse([]))
+
+
 optspec = """
 prog <optionset> [stuff...]
 prog [-t] <boggle>