Mercurial > public > mercurial-scm > hg
comparison mercurial/posix.py @ 23683:5edb387158a1
posix: quote the specified string only when it may have to be quoted
This patch makes "posix.shellquote" examine the specified string and
quote it only when it may have to be quoted for safety, like as the
previous patch for "windows.shellquote".
In fact, on POSIX environment, quoting itself doesn't cause issues
like issue4463. But (almost) equivalent quoting policy can avoid
examining test result differently on POSIX and Windows (even though
showing command line with "%r" causes such examination in
"test-extdiff.t").
The last hunk for "test-extdiff.t" in this patch isn't needed for the
previous patch for "windows.shellquote", because the code path of it
is executed only "#if execbit" (= avoided on Windows).
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Thu, 25 Dec 2014 23:33:26 +0900 |
parents | 7a5bcd471f2e |
children | d65ecb814fc0 |
comparison
equal
deleted
inserted
replaced
23682:1642eb429536 | 23683:5edb387158a1 |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from i18n import _ | 8 from i18n import _ |
9 import encoding | 9 import encoding |
10 import os, sys, errno, stat, getpass, pwd, grp, socket, tempfile, unicodedata | 10 import os, sys, errno, stat, getpass, pwd, grp, socket, tempfile, unicodedata |
11 import fcntl | 11 import fcntl, re |
12 | 12 |
13 posixfile = open | 13 posixfile = open |
14 normpath = os.path.normpath | 14 normpath = os.path.normpath |
15 samestat = os.path.samestat | 15 samestat = os.path.samestat |
16 oslink = os.link | 16 oslink = os.link |
313 # problems when Mercurial is used from both Cygwin and native | 313 # problems when Mercurial is used from both Cygwin and native |
314 # Windows, with other native tools, or on shared volumes | 314 # Windows, with other native tools, or on shared volumes |
315 def checklink(path): | 315 def checklink(path): |
316 return False | 316 return False |
317 | 317 |
318 _needsshellquote = None | |
318 def shellquote(s): | 319 def shellquote(s): |
319 if os.sys.platform == 'OpenVMS': | 320 if os.sys.platform == 'OpenVMS': |
320 return '"%s"' % s | 321 return '"%s"' % s |
322 global _needsshellquote | |
323 if _needsshellquote is None: | |
324 _needsshellquote = re.compile(r'[^a-zA-Z0-9._/-]').search | |
325 if not _needsshellquote(s): | |
326 # "s" shouldn't have to be quoted | |
327 return s | |
321 else: | 328 else: |
322 return "'%s'" % s.replace("'", "'\\''") | 329 return "'%s'" % s.replace("'", "'\\''") |
323 | 330 |
324 def quotecommand(cmd): | 331 def quotecommand(cmd): |
325 return cmd | 332 return cmd |