Certain strings set in the launch.json "args" will not be passed to python as arguments
See original GitHub issueEnvironment data
- VS Code version: 1.47.2
- Extension version (available under the Extensions sidebar): 2020.7.94776
- OS and version: macOS Catalina 10.15.5
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.2 64-bit
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): virtualenv
- Relevant/affected Python packages and their versions: N/A
- Relevant/affected Python-related VS Code extensions and their versions: N/A
- Value of the
python.languageServer
setting: Jedi
Expected behaviour
Putting “\s” anywhere in an argument in the “args” list of the launch.json file will then pass that argument “\s” to the python file I’m debugging
Actual behaviour
Instead, “” is passed as an argument to the python file
- Using “\s” resulted in “” being passed,
- Using “\s” resulted in “\s” being passed.
- Using “\\s” resulted in “\” being passed
Steps to reproduce & more detail:
- Create a python file
- Put a new item launch.json’s “arg” list, which contains a backslash, and then some letter, like “\s” or “\w”
- Debug the python file
You will notice that instead of “\s” being passed as an argument in the terminal, “” is passed (Just two double quotes)
I have also tried this with double backslashes. Using the same steps as above, but instead, I put “\s” in the “args” list. This also didn’t work, and I saw that “\s” was passed to my python file in the terminal. I added another slash, but “\\s” that only resulted in “\” being passed to my python file.
- Using one slash resulted in “” being passed,
- Using two slashes resulted in “\s” being passed.
- Using three slashes resulted in “\” being passed.
All I want is for “\s” to be passed as an argument to my python file.
Logs
In launch.json:
"args": [
"\s"
]
In Python Debug console: (Generated by the vscode-python extension)
cd /PATH/TO/DIR/src ; env /PATH/TO/PYTHON/python /Users/USERNAME/.vscode/extensions/ms-python.python-2020.7.94776/pythonFiles/lib/python/debugpy/launcher 50448 -- /PATH/TO/PYTHONFILE/foo.py ""
In launch.json:
"args": [
"\\s"
]
In Python Debug console: (Generated by the vscode-python extension)
cd /PATH/TO/DIR/src ; env /PATH/TO/PYTHON/python /Users/USERNAME/.vscode/extensions/ms-python.python-2020.7.94776/pythonFiles/lib/python/debugpy/launcher 50448 -- /PATH/TO/PYTHONFILE/foo.py \\s
In launch.json:
"args": [
"\\\s"
]
In Python Debug console: (Generated by the vscode-python extension)
cd /PATH/TO/DIR/src ; env /PATH/TO/PYTHON/python /Users/USERNAME/.vscode/extensions/ms-python.python-2020.7.94776/pythonFiles/lib/python/debugpy/launcher 50448 -- /PATH/TO/PYTHONFILE/foo.py \\
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
For bash at least, double quotes don’t disable escaping - only single quotes do. So
echo \\s
is equivalent toecho "\\s"
and toecho '\s'
.Other special symbols like
$
,()
, and&
are a bit different - there are some scenarios in which you want them to not be escaped (so that shell can perform variable and subshell expansion, for example), and others when you do want to pass them verbatim to the app.So, the debugger now allows you to control that by specifying
"argsExpansion": "none"
in your launch.json. The default setting is to enable shell expansion, because that’s what the extension was doing before the setting was added, and we didn’t want to break people with pre-existing launch.json configs relying on that behavior.The correct syntax is this one:
Because JSON itself treats
\
as a special character, so you need to escape it if you intend to use it verbatim.The reason why the command line VSCode generates contains
\\s
, is because it is in turn escaping it forbash
, which also requires backslashes to be escaped. If you doprint(sys.argv[1])
from inside Python, it should have the value that you expect.