mirror of https://github.com/python/cpython.git
Avoid unwanted behavior change in shlex.quote (see #9723).
I simplified the quote code to use a regex instead of a loop+test when I moved pipes.quote to shlex in 5966eeb0457d; Ezio Melotti pointed out that my regex contained redundant parts (now removed) and allowed non-ASCII characters (now disallowed). I think common UNIX shells don’t quote non-ASCII characters, but there’s no harm in doing so. We’ll see if users request a change.
This commit is contained in:
commit
7fc0394a12
|
@ -276,7 +276,7 @@ def split(s, comments=False, posix=True):
|
|||
return list(lex)
|
||||
|
||||
|
||||
_find_unsafe = re.compile(r'[^\w\d@%_\-\+=:,\./]').search
|
||||
_find_unsafe = re.compile(r'[^\w@%\-\+=:,\./]', re.ASCII).search
|
||||
|
||||
def quote(s):
|
||||
"""Return a shell-escaped version of the string *s*."""
|
||||
|
|
|
@ -176,7 +176,8 @@ def testCompat(self):
|
|||
|
||||
def testQuote(self):
|
||||
safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'
|
||||
unsafe = '"`$\\!'
|
||||
unicode_sample = '\xe9\xe0\xdf' # e + acute accent, a + grave, sharp s
|
||||
unsafe = '"`$\\!' + unicode_sample
|
||||
|
||||
self.assertEqual(shlex.quote(''), "''")
|
||||
self.assertEqual(shlex.quote(safeunquoted), safeunquoted)
|
||||
|
|
Loading…
Reference in New Issue