fabioz / PyDev.Debugger

Sources for the debugger used in PyDev, PyCharm and VSCode Python
Eclipse Public License 1.0
425 stars 122 forks source link

patch_arg_str_win incorrectly strips quotation marks on Windows. #204

Closed AlexGuo1998 closed 3 years ago

AlexGuo1998 commented 3 years ago

patch_arg_str_win will incorrectly strip quotation marks " on Windows.


To reproduce, try this code on Windows (popen.py):

from __future__ import print_function

import subprocess
import sys

if __name__ == '__main__':
    print('argv is: {}'.format(sys.argv))
    if len(sys.argv) == 1:
        print('spawn new process')
        p = subprocess.Popen(['python', __file__, 'a"b"c'])
        p.wait()
        print('new process finished')

Result with python popen.py, no debugger:

argv is: ['C:\\xxx\\popen.py']
spawn new process
argv is: ['C:\\xxx\\popen.py', 'a"b"c']
new process finished

Result with debugger attached:

Connected to pydev debugger (build 212.5284.44)
argv is: ['C:\\xxx\\popen.py']
spawn new process
argv is: ['C:\\xxx\\popen.py', 'abc']
new process finished

Notice that 'a"b"c' vs 'abc'.


This should be a bug in patch_arg_str_win:

https://github.com/fabioz/PyDev.Debugger/blob/bdec6121831a0799059d8e85705b4dab0e2ae882/_pydev_bundle/pydev_monkey.py#L658-L665

Printing original and patched arg_str indicates \ is incorrectly stripped.

original:
python C:\xxx\popen.py a\"b\"c
patched:
python C:\yyy\pydev\pydevd.py --port 30036 --client 127.0.0.1 --multiproc --file C:\xxx\popen.py a"b"c
fabioz commented 3 years ago

I just tried it here and it seems to work properly for me in pydevd... are you using the PyCharm version by any chance? --they have their own fork which may not be up-to-date here...

i.e.: the output I get is:

pydev debugger: starting (pid: 25708)
argv is: ['W:\\pydev.debugger\\check\\snippet7.py']
spawn new process
pydev debugger: starting (pid: 22028)
argv is: ['W:\\pydev.debugger\\check\\snippet7.py', 'a"b"c']
new process finished
AlexGuo1998 commented 3 years ago

Oh thanks for pointing out that. Actually I'm using PyCharm bundled pydevd. I'll redirect this issue to their tracker.