commands.{new,rename}: verify patch names
PATCH 1/1 commands.{new,rename}: verify patch names
Don't allow patches with invalid names. For example, a patch with a slash in the name will cause the underlying git command to fail, and stgit doesn't handle this error condition properly.
--- stgit/commands/new.py | 3 +++ stgit/commands/rename.py | 3 +++ stgit/utils.py | 5 +++++ 3 files changed, 11 insertions(+), 0 deletions(-)
stgit/commands/new.py +3 -0
@@ -61,6 +61,9 @@ def func(parser, options, args): name = args[0] if stack.patches.exists(name): raise common.CmdException('%s: patch already exists' % name) + + if not utils.check_patch_name(name): + raise common.CmdException('%s: invalid patch name' % name) else: parser.error('incorrect number of arguments')
stgit/commands/rename.py +3 -0
@@ -51,6 +51,9 @@ def func(parser, options, args): else: parser.error('incorrect number of arguments') + if not check_patch_name(new): + raise CmdException('%s: invalid patch name' % new) + out.start('Renaming patch "%s" to "%s"' % (old, new)) crt_series.rename_patch(old, new)
stgit/utils.py +5 -0
@@ -241,6 +241,11 @@ def make_patch_name(msg, unacceptable, default_name = 'patch'): patchname = default_name return find_patch_name(patchname, unacceptable) +def check_patch_name(name): + """Checks if the specified name is a valid patch name. For + technical reasons, we cannot allow a slash and other characters.""" + return len(name) > 0 and name[0] != '.' and re.search(r'[\x00-\x20]', name) is None + # any and all functions are builtin in Python 2.5 and higher, but not # in 2.4. if not 'any' in dir(__builtins__):
Quoted 4 lines · Max Kellermann
+def
check_patch_name(name):
+ """Checks if the specified name is a valid patch name. For
+ technical reasons, we cannot allow a slash and other characters."""
+ return len(name) > 0 and name[0] != '.' andre.search(r'[\x00-\x20]', name)is None
I don't quite understand how the above would filter out slashes.
There are also other types of names that won't work correctly in git, such as names starting with (double?) hyphens.
Does anyone know if it's explicitly documented anywhere which types of names are (meant to be) allowed for git refs?
Note that you can create refs with names that don't actually work correctly; e.g.,
sh$ git tag -- --foo
sh$ git rev-parse --foo
<failure>
- Gustav
Quoted 7 lines · Gustav Hållberg
Quoted 4 lines · Max Kellermann
+def
check_patch_name(name):
+ """Checks if the specified name is a valid patch name. For
+ technical reasons, we cannot allow a slash and other characters."""
+ return len(name) > 0 and name[0] != '.' andre.search(r'[\x00-\x20]', name)is NoneI don't quite understand how the above would filter out slashes.
Oh damn, you're right. I had slashes explicitly forbidden in a previous revision of my patch, that got lost when I added my "kill all whitespace" change. I'll resubmit.
Quoted 3 lines
sh$ git tag -- --foo
sh$ git rev-parse --foo
<failure>
I guess this is a problem because "git-rev-parse" doesn't follow the convention of the "--" option separator.