[PATCH] mq: reject new patch name containing leading/trailing whitespaces

Ryan McElroy rm at fb.com
Mon Mar 20 07:30:42 EDT 2017


These changes generally look good to me. A few small nit-picks inline.


On 3/20/17 8:21 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1489977517 -32400
> #      Mon Mar 20 11:38:37 2017 +0900
> # Node ID cede8eaf55e2fe68434c273cfd066512b5ca112e
> # Parent  a369482e9649478cbab5b08a204406a10ee66588
> mq: reject new patch name containing leading/trailing whitespaces
>
> We could create a patch of such name, but it wouldn't be processed properly
> by mq as parseseries() strips leading/trailing whitespaces.
>
> The test of default message (added by b9a16ed5acec) is no longer be useful
> so removed.
>
> This issue was reported as:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__bitbucket.org_tortoisehg_thg_issues_4693_&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Jw8rundaE7TbmqBYd1txIQ&m=FGt8q4fyGG6rxYkOEw26kt9XV26dLD5j-KUzcIEU4fk&s=-fasmyeWyfesMB7nneW80o055qlF7adTxbHE9bEV08s&e=
>
> diff --git a/hgext/mq.py b/hgext/mq.py
> --- a/hgext/mq.py
> +++ b/hgext/mq.py
> @@ -1116,6 +1116,9 @@ class queue(object):
>           if name in self._reserved:
>               raise error.Abort(_('"%s" cannot be used as the name of a patch')
>                                % name)
> +        if name != name.strip():
> +            # whitespaces are stripped by parseseries()

English nit-pick:

# whitespace is stripped by parseseries()

(your version is not incorrect, but it "sounds funny")

> +            raise error.Abort(_('patch name cannot begin or end with a space'))

I'd suggest 'patch name cannot begin or end with whitespace' because 
this will also reject tabs, right?

 >>> a = '\tfoo'
 >>> a == a.strip()

>           for prefix in ('.hg', '.mq'):
>               if name.startswith(prefix):
>                   raise error.Abort(_('patch name cannot begin with "%s"')
> diff --git a/tests/test-mq-qimport.t b/tests/test-mq-qimport.t
> --- a/tests/test-mq-qimport.t
> +++ b/tests/test-mq-qimport.t
> @@ -247,11 +247,28 @@ qimport -e --name with --force
>     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 a space
> +  [255]
> +  $ touch '.hg/patches/ bad.diff'
> +  $ hg qimport -e ' bad.diff'
> +  abort: patch name cannot begin or end with a space
> +  [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 a space
> +  [255]
> +  $ hg qimport non-existent-file --name 'foo '
> +  abort: patch name cannot begin or end with a space
> +  [255]
>   
>   qimport http:// patch with leading slashes in url
>   
> diff --git a/tests/test-mq-qnew.t b/tests/test-mq-qnew.t
> --- a/tests/test-mq-qnew.t
> +++ b/tests/test-mq-qnew.t
> @@ -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 @@ plain headers
>     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 a space
> +  abort: patch name cannot begin or end with a space
>     % qnew with name containing slash
>     abort: path ends in directory separator: foo/ (glob)
>     abort: "foo" already exists as a directory
> @@ -180,6 +184,8 @@ hg headers
>     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 a space
> +  abort: patch name cannot begin or end with a space
>     % qnew with name containing slash
>     abort: path ends in directory separator: foo/ (glob)
>     abort: "foo" already exists as a directory
> @@ -313,36 +319,3 @@ Test saving last-message.txt
>     > [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
> diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t
> --- a/tests/test-qrecord.t
> +++ b/tests/test-qrecord.t
> @@ -239,6 +239,12 @@ qrecord with bad patch name, should abor
>     $ hg qrecord .hg
>     abort: patch name cannot begin with ".hg"
>     [255]
> +  $ hg qrecord ' foo'
> +  abort: patch name cannot begin or end with a space
> +  [255]
> +  $ hg qrecord 'foo '
> +  abort: patch name cannot begin or end with a space
> +  [255]
>   
>   qrecord a.patch
>



More information about the Mercurial-devel mailing list