Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Python File in Terminal fails with & / ampersand in file path #8432

Closed
matthiasbier opened this issue Nov 7, 2019 · 8 comments
Closed
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on

Comments

@matthiasbier
Copy link

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:
2019-11-07_14h59_54

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
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): XXX

Expected behaviour

The command should enclose the file path with double quotes.
2019-11-07_15h08_42

This way the script executes correctly.

Thanks

@matthiasbier matthiasbier added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Nov 7, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Nov 7, 2019
@karrtikr karrtikr removed their assignment Nov 7, 2019
@karrtikr
Copy link

karrtikr commented Nov 7, 2019

I am able to confirm this, thanks.

@christine-e-smit
Copy link

christine-e-smit commented May 21, 2020

I am having this issue as well on Mac. When I run debug a script, I see:

sh-3.2$  env /NOT_A_REAL_PATH/python3/envs/vscode/bin/python /NOT_A_REAL_PATH/.vscode/extensions/ms-python.python-2020.5.80290/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher 53006 -- /NOT_A_REALPATH/bar.py https://some.url/?foo=1&bar=2

the &bar=2 doesn'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
Copy link

lisandromc commented May 28, 2020

This fails while using integrated terminal ("console": "integratedTerminal" ) or external terminal ("console": "externalTerminal" ). At launch.json:

"args": [
  "--uri", "https://example.com?a=X&b=Y"
],
"console": "integratedTerminal" 

Console output:

$  env /home/lisandro/example/venv/bin/python3.7 /home/lisandro/.vscode/extensions/ms-python.python-2020.5.80290/pythonFiles/lib/python/debugpy/wheels/debugpy/launcher 37491 -- -m main --uri https://example.com?a=X&b=Y

and the b parameter 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:

"args": [
  "--uri", "'https://example.com?a=X&b=Y'"
],

but it doesn't, because the single quotes ' become \':

$  env /home/lisandro/example/venv/bin/python3.7 /home/lisandro/.vscode/extensions/ms-python.python-2020.5.80290/pythonFiles/lib/python/debugpy/wheels/debugpy/launcher 42983 -- -m main --uri \'https://example.com?a=X&b=Y\'

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:

"args": [
  "--uri", "https://example.com?a=X&b=Y"
],
"console": "internalConsole" 

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
Copy link

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
Copy link

fireattack commented 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:

cmd /C "[...] \launcher 4538 -- f:\sync\code\python\_gists\_test.py "space in between" "

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:

cmd /C "[...] \launcher 4591 -- f:\sync\code\python\_gists\_test.py ampersand&in&between "

@fireattack
Copy link

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
Copy link

Facing the same issue. I am beginner. Let me check if I can debug this issue.

@github-actions github-actions bot removed the needs PR label Aug 9, 2022
@karrtikr karrtikr added the needs PR Ready to be worked on label Aug 9, 2022
@karrtikr
Copy link

Fixed by #18855.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on
Projects
None yet
Development

No branches or pull requests

8 participants