changeset 31556:448acdee9161

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/
author Yuya Nishihara <yuya@tcha.org>
date Mon, 20 Mar 2017 11:38:37 +0900
parents 7c7d3ad7ca5c
children 79d98e1b21a7
files hgext/mq.py tests/test-mq-qimport.t tests/test-mq-qnew.t tests/test-qrecord.t
diffstat 4 files changed, 33 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Fri Mar 10 16:18:43 2017 -0800
+++ b/hgext/mq.py	Mon Mar 20 11:38:37 2017 +0900
@@ -1116,6 +1116,10 @@
         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"')
--- a/tests/test-mq-qimport.t	Fri Mar 10 16:18:43 2017 -0800
+++ b/tests/test-mq-qimport.t	Mon Mar 20 11:38:37 2017 +0900
@@ -247,11 +247,28 @@
   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
 
--- a/tests/test-mq-qnew.t	Fri Mar 10 16:18:43 2017 -0800
+++ b/tests/test-mq-qnew.t	Mon Mar 20 11:38:37 2017 +0900
@@ -22,6 +22,8 @@
   >     hg qnew 'foo#bar'
   >     hg qnew 'foo:bar'
   >     hg qnew "`echo foo; echo bar`"
+  >     hg qnew ' foo'
+  >     hg qnew 'foo '
   > 
   >     hg qinit -c
   > 
@@ -112,6 +114,8 @@
   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
@@ -180,6 +184,8 @@
   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
@@ -313,36 +319,3 @@
   > [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	Fri Mar 10 16:18:43 2017 -0800
+++ b/tests/test-qrecord.t	Mon Mar 20 11:38:37 2017 +0900
@@ -239,6 +239,12 @@
   $ 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