classification
Title: Distutils doesn't quote Windows command lines properly
Type: behavior Stage:
Components: Distutils Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: tarek Nosy List: eric.araujo, mgiuca, r.david.murray, tarek
Priority: normal Keywords: patch

Created on 2010-06-13 05:22 by mgiuca, last changed 2010-06-14 05:09 by r.david.murray.

Files
File name Uploaded Description Edit
spawn.patch mgiuca, 2010-06-13 05:22 review
Messages (3)
msg107722 - (view) Author: Matt Giuca (mgiuca) Date: 2010-06-13 05:22
I discovered this investigating a bug report that python-cjson doesn't compile properly on Windows (http://pypi.python.org/pypi/python-cjson). Cjson's setup.py asks distutils to compile with the flag '-DMODULE_VERSION="1.0.5"', but distutils.spawn._nt_quote_args is not escaping the quotes correctly.

Specifically, the current behaviour is:
>>> distutils.spawn._nt_quote_args(['-DMODULE_VERSION="1.0.5"'])
['-DMODULE_VERSION="1.0.5"']

I expect the following:
>>> distutils.spawn._nt_quote_args(['-DMODULE_VERSION="1.0.5"'])
['"-DMODULE_VERSION=""1.0.5"""']

Not surprising, since that function contains a big comment:
    # XXX this doesn't seem very robust to me -- but if the Windows guys
    # say it'll work, I guess I'll have to accept it.  (What if an arg
    # contains quotes?  What other magic characters, other than spaces,
    # have to be escaped?  Is there an escaping mechanism other than
    # quoting?)

It only escapes spaces, and that's it. I've proposed a patch which escapes the following characters properly: "&()<>^| (as far as I can tell, these are the "reserved" characters on Windows).

Note: I did not escape * or ?, the wildcard characters. As far as I can tell, these only have special meaning on the command-line itself, and not when supplied to a program.

Alternatively, it could call subprocess.list2cmdline (but there seem to be issues with that: http://bugs.python.org/issue8972).
msg107751 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-13 20:58
Distutils is frozen, because even fixing blatant bugs breaks third-party code that relies on internals. Can you check your bug with a Distutils2 checkout from hg.python.org/distutils2?
msg107772 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-06-14 05:09
Note that list2cmdline does correct quoting (which includes the "s) if you are passing the string directly to a program.  In that case cmd.exe's metacharacters aren't special.  (As I noted in issue 8972, I believe that list2cmdline's current quoting of '|' characters is in error).

Perhaps a canonical list2cmdline actually belongs in shutil?
History
Date User Action Args
2010-06-14 05:09:14r.david.murraysetnosy: + r.david.murray
messages: + msg107772
2010-06-13 20:58:39eric.araujosetnosy: + eric.araujo
messages: + msg107751
2010-06-13 05:23:47mgiucasettype: behavior
2010-06-13 05:22:51mgiucacreate