R. David Murray added the comment:

There are two features of this I have questions about.  If I'm understanding 
correctly, if passed a quoted string you are not re-quoting it, but you are 
always stripping a trailing slash even if it is inside quotes.

For the first, that seems wrong.  Either we should be quoting the quotes, or we 
should assume that if passed a string that starts and ends with quotes, that it 
is already fully quoted, and not change it.

For the second, doesn't that potentially change the semantics of the string 
passed in?  You can't actually know that the backslash is part of a path, nor 
can you be sure that a trailing backslash is not significant even if it is a 
path.  And in fact if there is a backslash before a double quote, arguably that 
is supposed to be a double quote that doesn't end the string (see point one 
above).

I tried list2cmdline, and what it does is to backslash escape appropriately, 
including preserving blackslashes that are in front of double quotes, and does 
not add surrounding quotes if there are no internal blanks.  I think 
list2cmdline is correct here (and it has certainly seen a lot of use), and I 
think we should either replicate its logic or just use it.

Now, subprocess calls CreateProcess, while distutils calls os.spawnv, but my 
understanding is that the quoting rules are the same (that is, that the CRT's 
_spawnv ultimately calls CreateProcess with the arguments joined by blanks).  

Since issue 8972 has been resolved by fixing the broken behavior, I think we 
should just use list2cmdline.  We could leave _nt_quote_args alone and replace 
the call to it in _spawn_nt with:

  cmd = [list2cmdline([arg]) for arg in cmd]

or we could put the fix in _nt_quote_args.  The backward compatibility calculus 
is...not obvious :(

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8987>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to