[PATCH STABLE] shellquote: fix missing quotes for empty string

Augie Fackler raf at durin42.com
Wed Feb 11 08:36:53 CST 2015


On Feb 11, 2015, at 6:40 AM, Yuya Nishihara <yuya at tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1423652227 -32400
> #      Wed Feb 11 19:57:07 2015 +0900
> # Branch stable
> # Node ID de0192120a2ae23adb5b9749c1ed868913aecdc6
> # Parent  942a5a34b2d0611ab284380fbe45b9bb1897af98
> shellquote: fix missing quotes for empty string

Queued this for stable, thanks.

> 
> "hg kdiff3 -rREV" did not work because 1642eb429536 and 5edb387158a1 failed
> to handle empty argument.
> 
> diff --git a/mercurial/posix.py b/mercurial/posix.py
> --- a/mercurial/posix.py
> +++ b/mercurial/posix.py
> @@ -322,7 +322,7 @@ def shellquote(s):
>     global _needsshellquote
>     if _needsshellquote is None:
>         _needsshellquote = re.compile(r'[^a-zA-Z0-9._/-]').search
> -    if not _needsshellquote(s):
> +    if s and not _needsshellquote(s):
>         # "s" shouldn't have to be quoted
>         return s
>     else:
> diff --git a/mercurial/windows.py b/mercurial/windows.py
> --- a/mercurial/windows.py
> +++ b/mercurial/windows.py
> @@ -159,7 +159,7 @@ def shellquote(s):
>         # they are used as a part of path name (and the latter doesn't
>         # work as "escape character", like one on posix) on Windows
>         _needsshellquote = re.compile(r'[^a-zA-Z0-9._:/\\-]').search
> -    if not _needsshellquote(s) and not _quotere.search(s):
> +    if s and not _needsshellquote(s) and not _quotere.search(s):
>         # "s" shouldn't have to be quoted
>         return s
>     return '"%s"' % _quotere.sub(r'\1\1\\\2', s)
> diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t
> --- a/tests/test-extdiff.t
> +++ b/tests/test-extdiff.t
> @@ -182,6 +182,22 @@ TODO
>   running "*/bin/echo --foo='sp ace' 'sp ace' --bar='sp ace' 'sp ace'" in * (glob)
> #endif
> 
> +Empty argument must be quoted
> +
> +  $ cat <<EOF >> $HGRCPATH
> +  > [extdiff]
> +  > kdiff3 = echo
> +  > [merge-tools]
> +  > kdiff3.diffargs=--L1 \$plabel1 --L2 \$clabel \$parent \$child
> +  > EOF
> +#if windows
> +  $ hg --debug kdiff3 -r0 | grep '^running'
> +  running 'echo --L1 "@0" --L2 "" a.8a5febb7f867 a' in * (glob)
> +#else
> +  $ hg --debug kdiff3 -r0 | grep '^running'
> +  running "echo --L1 '@0' --L2 '' a.8a5febb7f867 a" in * (glob)
> +#endif
> +
> #if execbit
> 
> Test extdiff of multiple files in tmp dir:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150211/ce2011a6/attachment.pgp>


More information about the Mercurial-devel mailing list