mq: reject new patch name containing leading/trailing whitespace
authorYuya Nishihara <yuya@tcha.org>
Mon, 20 Mar 2017 11:38:37 +0900
changeset 36537 448acdee91613b1f3dcc14569b164849069cac0f
parent 36536 7c7d3ad7ca5cb34966e34491153a420fd7acf4f0
child 36538 79d98e1b21a7afc1045a03a1aaf27ee598b8bbb8
push id476
push usergszorc@mozilla.com
push dateWed, 22 Mar 2017 06:06:07 +0000
mq: reject new patch name containing leading/trailing whitespace We could create a patch of such name, but it wouldn't be processed properly by mq as parseseries() strips leading/trailing whitespace. The test of default message (added by b9a16ed5acec) is no longer be useful so removed. This issue was reported as: https://bitbucket.org/tortoisehg/thg/issues/4693/
hgext/mq.py
tests/test-mq-qimport.t
tests/test-mq-qnew.t
tests/test-qrecord.t
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1111,16 +1111,20 @@ class queue(object):
             _("local changed subrepos found, qrefresh first")
         return checklocalchanges(repo, force, excsuffix)
 
     _reserved = ('series', 'status', 'guards', '.', '..')
     def checkreservedname(self, name):
         if name in self._reserved:
             raise error.Abort(_('"%s" cannot be used as the name of a patch')
                              % name)
+        if name != name.strip():
+            # whitespace is stripped by parseseries()
+            raise error.Abort(_('patch name cannot begin or end with '
+                                'whitespace'))
         for prefix in ('.hg', '.mq'):
             if name.startswith(prefix):
                 raise error.Abort(_('patch name cannot begin with "%s"')
                                  % prefix)
         for c in ('#', ':', '\r', '\n'):
             if c in name:
                 raise error.Abort(_('%r cannot be used in the name of a patch')
                                  % c)
--- a/tests/test-mq-qimport.t
+++ b/tests/test-mq-qimport.t
@@ -242,21 +242,38 @@ qimport -e --name with --force
 
   $ hg qimport --force -e --name this-name-is-better 3.diff
   renaming 3.diff to this-name-is-better
   adding this-name-is-better to series file
   $ hg qser
   this-name-is-better
   url.diff
 
+import patch of bad filename
+
+  $ touch '../ bad.diff'
+  $ hg qimport '../ bad.diff'
+  abort: patch name cannot begin or end with whitespace
+  [255]
+  $ touch '.hg/patches/ bad.diff'
+  $ hg qimport -e ' bad.diff'
+  abort: patch name cannot begin or end with whitespace
+  [255]
+
 qimport with bad name, should abort before reading file
 
   $ hg qimport non-existent-file --name .hg
   abort: patch name cannot begin with ".hg"
   [255]
+  $ hg qimport non-existent-file --name ' foo'
+  abort: patch name cannot begin or end with whitespace
+  [255]
+  $ hg qimport non-existent-file --name 'foo '
+  abort: patch name cannot begin or end with whitespace
+  [255]
 
 qimport http:// patch with leading slashes in url
 
 set up hgweb
 
   $ cd ..
   $ hg init served
   $ cd served
--- a/tests/test-mq-qnew.t
+++ b/tests/test-mq-qnew.t
@@ -17,16 +17,18 @@
   >     hg qnew guards
   >     hg qnew .
   >     hg qnew ..
   >     hg qnew .hgignore
   >     hg qnew .mqfoo
   >     hg qnew 'foo#bar'
   >     hg qnew 'foo:bar'
   >     hg qnew "`echo foo; echo bar`"
+  >     hg qnew ' foo'
+  >     hg qnew 'foo '
   > 
   >     hg qinit -c
   > 
   >     echo '% qnew with name containing slash'
   >     hg qnew foo/
   >     hg qnew foo/bar.patch
   >     hg qnew foo
   >     hg qseries
@@ -107,16 +109,18 @@ plain headers
   abort: "guards" cannot be used as the name of a patch
   abort: "." cannot be used as the name of a patch
   abort: ".." cannot be used as the name of a patch
   abort: patch name cannot begin with ".hg"
   abort: patch name cannot begin with ".mq"
   abort: '#' cannot be used in the name of a patch
   abort: ':' cannot be used in the name of a patch
   abort: '\n' cannot be used in the name of a patch
+  abort: patch name cannot begin or end with whitespace
+  abort: patch name cannot begin or end with whitespace
   % qnew with name containing slash
   abort: path ends in directory separator: foo/ (glob)
   abort: "foo" already exists as a directory
   foo/bar.patch
   popping foo/bar.patch
   patch queue now empty
   % qnew with uncommitted changes
   uncommitted.patch
@@ -175,16 +179,18 @@ hg headers
   abort: "guards" cannot be used as the name of a patch
   abort: "." cannot be used as the name of a patch
   abort: ".." cannot be used as the name of a patch
   abort: patch name cannot begin with ".hg"
   abort: patch name cannot begin with ".mq"
   abort: '#' cannot be used in the name of a patch
   abort: ':' cannot be used in the name of a patch
   abort: '\n' cannot be used in the name of a patch
+  abort: patch name cannot begin or end with whitespace
+  abort: patch name cannot begin or end with whitespace
   % qnew with name containing slash
   abort: path ends in directory separator: foo/ (glob)
   abort: "foo" already exists as a directory
   foo/bar.patch
   popping foo/bar.patch
   patch queue now empty
   % qnew with uncommitted changes
   uncommitted.patch
@@ -308,41 +314,8 @@ Test saving last-message.txt
   
   
   test saving last-message.txt
 
   $ cat >> .hg/hgrc <<EOF
   > [hooks]
   > pretxncommit.unexpectedabort =
   > EOF
-
-#if unix-permissions
-
-Test handling default message with the patch filename with tail whitespaces
-
-  $ cat > $TESTTMP/editor.sh << EOF
-  > echo "==== before editing"
-  > cat \$1
-  > echo "===="
-  > echo "[mq]: patch        " > \$1
-  > EOF
-
-  $ rm -f .hg/last-message.txt
-  $ hg status
-  $ HGEDITOR="sh $TESTTMP/editor.sh" hg qnew -e "patch "
-  ==== before editing
-  
-  
-  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
-  HG: Leave message empty to use default message.
-  HG: --
-  HG: user: test
-  HG: branch 'default'
-  HG: no files changed
-  ====
-  $ cat ".hg/patches/patch "
-  # HG changeset patch
-  # Parent  0000000000000000000000000000000000000000
-  
-
-  $ cd ..
-
-#endif
--- a/tests/test-qrecord.t
+++ b/tests/test-qrecord.t
@@ -234,16 +234,22 @@ Whole diff
    someone
    up
 
 qrecord with bad patch name, should abort before prompting
 
   $ hg qrecord .hg
   abort: patch name cannot begin with ".hg"
   [255]
+  $ hg qrecord ' foo'
+  abort: patch name cannot begin or end with whitespace
+  [255]
+  $ hg qrecord 'foo '
+  abort: patch name cannot begin or end with whitespace
+  [255]
 
 qrecord a.patch
 
   $ hg qrecord -d '0 0' -m aaa a.patch <<EOF
   > y
   > y
   > n
   > y