[Python-checkins] cpython (merge 3.2 -> default): Avoid unwanted behavior change in shlex.quote (see #9723).
eric.araujo
python-checkins at python.org
Fri Aug 12 18:03:54 CEST 2011
http://hg.python.org/cpython/rev/6ae0345a7e29
changeset: 71824:6ae0345a7e29
parent: 71787:69b354a8c90f
parent: 71823:8032ea4c3619
user: Éric Araujo <merwok at netwok.org>
date: Tue Aug 09 23:18:06 2011 +0200
summary:
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.
files:
Lib/shlex.py | 2 +-
Lib/test/test_shlex.py | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Lib/shlex.py b/Lib/shlex.py
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -276,7 +276,7 @@
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*."""
diff --git a/Lib/test/test_shlex.py b/Lib/test/test_shlex.py
--- a/Lib/test/test_shlex.py
+++ b/Lib/test/test_shlex.py
@@ -176,7 +176,8 @@
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)
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list