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

Tasks: Single/double quotes not quoted/escaped #46709

Closed
chrmarti opened this issue Mar 27, 2018 · 8 comments
Closed

Tasks: Single/double quotes not quoted/escaped #46709

chrmarti opened this issue Mar 27, 2018 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues verified Verification succeeded
Milestone

Comments

@chrmarti
Copy link
Contributor

1.22 insiders on Linux. Testing #46567.

Default quoting does not quote/escape when using a single or double quote in an argument or the command name.

@chrmarti
Copy link
Contributor Author

Same when using a task provider.

@ramya-rao-a
Copy link
Contributor

Same for $

...
"command": "echo",
"args: [
   {
      "value": "hello $PATH",
      "quoting": "escape"
    }
]

This will print the $PATH variable, I was expecting the $ to be escaped

@dbaeumer dbaeumer added the tasks Task system issues label Mar 28, 2018
@dbaeumer dbaeumer added this to the March 2018 milestone Mar 28, 2018
@dbaeumer
Copy link
Member

@chrmarti and I discussed this a little and here is what we should do:

  • if an argument has a ' or " in it and an escape is requested they need to be escaped as well.
  • if an argument has a ' in it and strong quoting is requested the ' must be escaped as well.
  • if an argument has a " in it and weak quoting is requested the " must be escaped as well.

This might be problematic so under cmd.exe since it doesn't support escaping. I fall back to strong quoting for cmd.exe.

@ramya-rao-a I think the current behaviour is correct since escaping is more used like weak quoting than strong quoting. So echo Hello\ $PATH is more like echo "Hello $PATH" than echo 'Hello $PATH'. Please ping if you disagree.

@dbaeumer
Copy link
Member

More complicated. In both bash and PowerShell you can't escape stuff in a strong quoted arg. This makes sense since in a strong quotes string is not interpreted by the shell.

@dbaeumer
Copy link
Member

You can escape " in weak quoting. There is not need to escape ' in weak quotes since ' will not be interpreted in weak quoted args.

@dbaeumer
Copy link
Member

Tested a little more:

  • under bash you can't create a single strong quoted argument that contains a '. Even not when you escape it
  • under PowerShell you can by putting '' into the string (e.g. echo 'Hello '' World')

@dbaeumer
Copy link
Member

Here is what I fixed:

  • if escaping is requested I escape " and ' as well.
  • I will not do anything special for cases where a string contains " or ' and weak or strong quoting (including default) is requested. Reason being is that this can not be supported on all shell in all combinations and it will be hard to explain when we do something magically and when not. If users want to have such args they need to do the write thing in the arg and may be have special command per OS / Shell.

@dbaeumer
Copy link
Member

To verify:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "dir",
            "type": "shell",
            "command": "echo",
            "args": [
                {
                    "value": "'Hello World'",
                    "quoting": "escape"
                }
            ],
            "problemMatcher": []
        }
    ]
}

Should print 'Hello Works'

@Tyriar Tyriar added the bug Issue identified by VS Code Team member as probable bug label Mar 30, 2018
@ramya-rao-a ramya-rao-a added the verified Verification succeeded label Mar 30, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants