You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Run Python File in Terminal fails with & / ampersand in file path #8432
The Command "Run Python File in Terminal" does not escape special chars in the file path and execution fails with an error. In my case the file path contains an ampersand and the errors states that you can not use the &-char in string literals:
Environment data
VS Code version: 1.39.2
Extension version (available under the Extensions sidebar): 2019.10.44104
OS and version: WIndows 10 10.0.18362
Python version (& distribution if applicable, e.g. Anaconda): Python 3.9.0 32-bit
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
Relevant/affected Python packages and their versions: XXX
This issue appears to be exactly the same as microsoft/vscode#66738, although that one involved a node script. This makes me wonder if the issue is actually with the debugger rather than with the python extension.
I'm having the same problem as well. There is no way to escape & so that bash doesn't misinterpret it. Adding a single quote ' gets converted to \' by the debugger. Also tried using \" instead of single quote but that doesn't work either.
So for ampersands, VS Code should do the same, since otherwise it would be interpreted as something else by most of terminals as mentioned above, but it doesn't:
It looks to me that this isn't hard to fix (quote it when there are ampersands in args string(s), just like what we already do for space), and the impact of the bug is relatively large: you can't debug anything with ampersand in args.
With filenames, I can somewhat get away by renaming the files myself, but I can't really avoid them in args for things like URLs with query strings.
Activity
karrtikr commentedon Nov 7, 2019
I am able to confirm this, thanks.
christine-e-smit commentedon May 21, 2020
I am having this issue as well on Mac. When I run debug a script, I see:
the
&bar=2doesn't come through to my script.This issue appears to be exactly the same as microsoft/vscode#66738, although that one involved a node script. This makes me wonder if the issue is actually with the debugger rather than with the python extension.
lisandromc commentedon May 28, 2020
This fails while using integrated terminal (
"console": "integratedTerminal") or external terminal ("console": "externalTerminal"). At launch.json:Console output:
and the
bparameter never reaches the code.This happens because, in BASH, the & sign has a special meaning. The actual problem is that there seems to be no way to escape it. This should work:
but it doesn't, because the single quotes
'become\':and so quoting makes no difference, other than further screwing the URL argument into
"'https://example.com?a=X"As I understand it, the extension should not escape single quotes in the arguments.
Note that this issue doesn't happen while using the internal console:
The problem with internal console is that now we lose all debugging output, which more or less defeats the purpose.
Version: 1.44.2
Commit: ff915844119ce9485abfe8aa9076ec76b5300ddd
Date: 2020-04-16T17:50:03.709Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.3.0-46-generic
alaa-ismail commentedon Jun 3, 2020
I'm having the same problem as well. There is no way to escape
&so that bash doesn't misinterpret it. Adding a single quote'gets converted to\'by the debugger. Also tried using\"instead of single quote but that doesn't work either.Version: 1.45.1
Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a
Date: 2020-05-14T08:27:22.494Z
Electron: 7.2.4
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.6.15-1-MANJARO
fireattack commentedon Aug 22, 2020
Just want to mention, in addition to Linux and Mac, this issue happens in Windows (with CMD) as well.
I think the cause is pretty straightforward:
When the args (or file path) have spaces, VS Code will automatically quote them, so there is no ambiguity:
So for ampersands, VS Code should do the same, since otherwise it would be interpreted as something else by most of terminals as mentioned above, but it doesn't:
fireattack commentedon Jan 2, 2021
Any chance to have someone looking into this?
It looks to me that this isn't hard to fix (quote it when there are ampersands in args string(s), just like what we already do for space), and the impact of the bug is relatively large: you can't debug anything with ampersand in args.
With filenames, I can somewhat get away by renaming the files myself, but I can't really avoid them in args for things like URLs with query strings.
Thanks!
Shrirang97 commentedon May 9, 2021
Facing the same issue. I am beginner. Let me check if I can debug this issue.
karrtikr commentedon Dec 19, 2022
Fixed by #18855.