You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2010/11/10 17:50:46 UTC
svn commit: r1033584 -
/subversion/trunk/subversion/tests/cmdline/svntest/main.py
Author: julianfoad
Date: Wed Nov 10 16:50:46 2010
New Revision: 1033584
URL: http://svn.apache.org/viewvc?rev=1033584&view=rev
Log:
Fix Windows command-line argument quoting in the Python test harness.
Arguments ending with a backslash were not correctly quoted, among other
issues. This reverts r875257.
* subversion/tests/cmdline/svntest/main.py
(_quote_arg): Do the quoting more correctly, using subprocess.list2cmdline()
on Windows and in-line code on Unix.
(open_pipe): Pass the list of arguments directly to subprocess.Popen()
instead of trying to quote it ourselves on Windows. Use our own quoting
only for display purposes.
Modified:
subversion/trunk/subversion/tests/cmdline/svntest/main.py
Modified: subversion/trunk/subversion/tests/cmdline/svntest/main.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/main.py?rev=1033584&r1=1033583&r2=1033584&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/main.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/main.py Wed Nov 10 16:50:46 2010
@@ -345,23 +345,22 @@ _safe_arg_re = re.compile(r'^[A-Za-z\d\.
def _quote_arg(arg):
"""Quote ARG for a command line.
- Simply surround every argument in double-quotes unless it contains
+ Return a quoted version of the string ARG, or just ARG if it contains
only universally harmless characters.
WARNING: This function cannot handle arbitrary command-line
- arguments. It can easily be confused by shell metacharacters. A
- perfect job would be difficult and OS-dependent (see, for example,
- http://msdn.microsoft.com/library/en-us/vccelng/htm/progs_12.asp).
- In other words, this function is just good enough for what we need
- here."""
+ arguments: it is just good enough for what we need here."""
arg = str(arg)
if _safe_arg_re.match(arg):
return arg
+
+ if windows:
+ # Note: subprocess.list2cmdline is Windows-specific.
+ return subprocess.list2cmdline([arg])
else:
- if os.name != 'nt':
- arg = arg.replace('$', '\$')
- return '"%s"' % (arg,)
+ # Quoting suitable for most Unix shells.
+ return "'" + arg.replace("'", "'\\''") + "'"
def open_pipe(command, bufsize=0, stdin=None, stdout=None, stderr=None):
"""Opens a subprocess.Popen pipe to COMMAND using STDIN,
@@ -377,15 +376,7 @@ def open_pipe(command, bufsize=0, stdin=
if (sys.platform == 'win32') and (command[0].endswith('.py')):
command.insert(0, sys.executable)
- # Quote only the arguments on Windows. Later versions of subprocess,
- # 2.5.2+ confirmed, don't require this quoting, but versions < 2.4.3 do.
- if sys.platform == 'win32':
- args = command[1:]
- args = ' '.join([_quote_arg(x) for x in args])
- command = command[0] + ' ' + args
- command_string = command
- else:
- command_string = ' '.join(command)
+ command_string = command[0] + ' ' + ' '.join(map(_quote_arg, command[1:]))
if not stdin:
stdin = subprocess.PIPE