]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Reject path arguments that start with '-' with a usage error. 219/head
authorDaira Hopwood <daira@jacaranda.org>
Mon, 28 Dec 2015 20:45:14 +0000 (20:45 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 28 Dec 2015 20:52:51 +0000 (20:52 +0000)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/util/encodingutil.py

index d14b08f6be448782a454fefd1da22d6d8e9e45eb..80fcb37850bc4f8ef9f1e0b0a1c549e649af7540 100644 (file)
@@ -88,12 +88,16 @@ def argv_to_unicode(s):
         raise usage.UsageError("Argument %s cannot be decoded as %s." %
                                (quote_output(s), io_encoding))
 
-def argv_to_abspath(s):
+def argv_to_abspath(s, long_path=True):
     """
     Convenience function to decode an argv element to an absolute path, with ~ expanded.
     If this fails, raise a UsageError.
     """
-    return abspath_expanduser_unicode(argv_to_unicode(s))
+    decoded = argv_to_unicode(s)
+    if decoded.startswith(u'-'):
+        raise usage.UsageError("Path argument %s cannot start with '-'.\nUse %s if you intended to refer to a file."
+                               % (quote_output(s), quote_output(os.path.join('.', s))))
+    return abspath_expanduser_unicode(decoded, long_path=long_path)
 
 def unicode_to_argv(s, mangle=False):
     """