-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Shell commands in launch.json args are escaped #149910
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
Comments
I will copy my answer from #149391 (comment) and we can continue the discussion here The history is this - we were not fully escaping args, making it impossible to pass some special characters to a program as args. #145265. I think we never intended to enable arbitrary shell scripts in launch.json args, but it worked because arg escaping was incomplete. Now we escape all special characters in args for the shell. My view is that args should be arguments passed to a program, not a shell script which only works in a particular shell. Since lots of people were using < and > for input and output redirection, our compromise was not escaping those characters when they are alone in an arg. But other characters will be escaped so they can be passed literally to a program. There might be another way you can get the same transformation like by doing it in your .py file. That would be platform-independent too. Or, maybe you can start a shell script that runs your code with these options and use an "attach" config to attach to it. |
This does show that I am not escaping backticks, which I guess is a big omission |
Please just leave the backticks then! I think anyway a lot of people to use output of other scripts as arguments in the launch configuration, so it would be more appretierend to just have a configuration option to escape special chars if one wants that... |
Examples from other issues:
|
@roblourens I'm not sure if this is the exact same issue, but seems related and is definitely non obvious. In code version
Notice the $ ts-node -T main.js --option-one=test "--option-two=-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvmcQzmJeN9+Td84ExBNl
SItvghT.... ....9b9
5h0DGNShR0vKa2qGcTIIwTMCAwEAAQ==
-----END PUBLIC KEY-----", While in $ ts-node -T main.js --option-one=test --option-two=-----BEGIN\ PUBLIC\ KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvmcQzmJeN9+Td84ExBNl
SItvghT.... ....9b9
5h0DGNShR0vKa2qGcTIIwTMCAwEAAQ==
-----END\ PUBLIC\ KEY----- Notice that in the older release double quotes are used for the entire argument (including the option name itself - but this doesn't matter). A bash specific 'one-line' implementation could be to use Since the escape logic is hidden, I cannot use either approach since the dollar and single quotes are escaped, and I cannot escape double quotes myself since the escaped double quote is output in terminal. I also tried the 'hidden' flag but it didn't work
|
@roblourens there is already a DAP feature request to support passing arguments unescaped to the shell. |
@roblourens supporting unescaped command line arguments generically in VS Code is not trivial because VS Code knows nothing about launch.json properties that represent those arguments. Properties like The cleanest approach to address the "unescaped arguments" problem would be to:
The main disadvantage of the clean approach is that each debug extension has to to opt-into the feature by introducing and implementing new debug configuration properties. This takes time and can lead to inconsistencies in naming, since each extension is free to choose its own property names. I wonder whether we could find a robust and elegant way to solve the problem in VS Code only. E.g. something like this:
One problem with that approach is that debug adapters are free to call Any better ideas to solve the problem? |
The first solution is what I had in mind. Yes, every debug adapter has to add a flag independently, but if we get a fix in the python and node DA's, that solves most of the problem. And I think breaking other calls to runInTerminal like you describe would be a real risk. |
@roblourens If we go that route, then we should probably give some advice what new properties to use and how to name them. |
Maybe |
@connor4312 suggested a string format for
I think it would be useful to be able to toggle this behavior without having to reformat your args, with a simple bool toggle in the launch config. On the other hand, it makes more sense to have a string where the format of the array doesn't actually matter, and "toggling" this probably won't actually happen that often. I'll try it and see how it feels. @karthiknadig heads up, I will be filing a feature request on the python extension to adopt this for launch configs as well. vscode-python can implement it independently however it wants to, but might as well match js-debug for consistency. I'm wondering whether you have a preference on the shape in the launch config. |
@roblourens is this for |
Yes |
Yes, I was proposing the string (instead of string array) format for args in various feature requests. One advantage of a single string "command line" is the ability to use an interactive "input variable" for it (where the user can enter the full command line in a prompt). |
Closing this since the DAP change is implemented in vscode, we can continue the discussion about launch config format in microsoft/vscode-js-debug#1335. |
@roblourens great that you are working on this! Seeing that the discussion is now moved to a javascript-specific repo - will this be implemented for all languages? My use case is that I want to run a debugger session with the current date as a parameter to the program to be debugged. I can get the current date with |
@hansmbakker VS Code's underlying support for this feature will work for all debuggers, but they have to adopt it in their implementation (which depends on the extension author). Yes, it should be possible to use `date -I` (in backticks) for unix shells. |
We have written the needed data into your clipboard because it was too large to send. Please paste.
Issue Type: Bug
Hello,
I worked with this launch configuration for ages now:
The special part is this line in the args:
It calls the gen_addons_path script, what returns it then. This worked all the time, but as I wanted to start working today, it gives me this:
bash: /usr/bin/gen_addons_path -d /workspace: No such file or directory
Maybe it's because of the escape characters in the call itself:
If I remove the arguments for this script, the call seems to work, but then the script fails, as it needs the arguments obviously...
So what's the issue here, did you guys update something on the vs-code-server? If so, please revert it...
VS Code version: Code 1.67.2 (c3511e6, 2022-05-17T18:23:40.286Z)
OS version: Linux x64 5.15.40-xanmod1-tt
Restricted Mode: No
Remote OS version: Linux x64 5.15.40-xanmod1-tt
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Extensions (30)
A/B Experiments
The text was updated successfully, but these errors were encountered: