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

Task with escaped double quote now fails due to improper evaluation #50131

Closed
kevinbeaudoin opened this issue May 18, 2018 · 4 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues

Comments

@kevinbeaudoin
Copy link

We are using custom task in vscode to compile some C# solutions using msbuild. The tasks used to run just fine but with latest upgrade our task now fails because double quote escaping isn't performed correctly (see example below)

  • VSCode Version: 1.23.1 (used to work in 1.22)
  • OS Version: Windows 8.1

Steps to Reproduce:

  1. Create a task similar to this one (Notice the quote escape for the Any CPU param):
    {
    "label": "Build MySolutionName.sln",
    "type": "shell",
    "command": "msbuild",
    "isBackground": false,
    "options": {
    "cwd": "C:\Program Files (x86)\MSBuild\14.0\Bin"
    },
    "args": [
    "${workspaceRoot}\..\..\MySolutionName.sln",
    "/property:Configuration=Debug",
    "/property:platform="Any CPU"",
    "/v:m",
    "/p:WarningLevel=0"
    ],
    "group": "build",
    "problemMatcher": []
    },

  2. Here is the task that vscode tries to run (Notice the issue with the part where we specify the Any CPU :
    Executing task: msbuild MySolutionName.sln /property:Configuration=Debug "/property:platform="Any CPU"" /v:m /p:WarningLevel=0

  3. Before the upgrade the task was run like below:
    Executing task: msbuild MySolutionName.sln /property:Configuration=Debug /property:platform="Any CPU" /v:m /p:WarningLevel=0

Does this issue occur when all extensions are disabled?: Yes

@vscodebot vscodebot bot added the tasks Task system issues label May 18, 2018
@dbaeumer
Copy link
Member

@kevinbeaudoin actually shell tasks with args quoting and spaces were poorly supported and there should have been an warning / error in the task output informing that if a shell task specifies args with spaces they should be folded into the command. I apologies if this didn't happen in your case (but I am confident it did looking at your example). (side note: the reason for this is that shell take a command line as arguments and not a command and args and VS Code always tried to create a command line from the command and the args but did a poor job on doing this correctly in the past)

To make the story better we improved the quoting/escaping behavior in 1.22 in the following way:

  • args with spaces are now allowed and we quote such args strongly.
  • users can control how args are quoted by providing a literal and not a single string.

For complex command lines where only parts inside the command line should be quoted the recommendation is to write one single command line. In our example something like:

"command": "msbuild ${workspaceRoot}....\MySolutionName.sln /property:Configuration=Debug /property:platform="Any CPU" /v:m /p:WarningLevel=0"

since this gives you the biggest control over the command. Since users uses args to split the long command line into lines I added support to provide a string[] for a command for the next release: So with 1.24 you will be able to write:

"command": [
"msbuild",
"${workspaceRoot}....\MySolutionName.sln",
"/property:Configuration=Debug",
"/property:platform="Any CPU",
"/v:m"
"/p:WarningLevel=0"
]

Noticed that there are no args. You construct a command line.

On think I take away from this is that for args we should off a "leave as is" quoting rule which leaves the args untouched even if it has spaces. I will add that.

@dbaeumer
Copy link
Member

My last sentence is not correct. The fix here is to detect that "Any CPU" is quoted and leave it untouched.

@dbaeumer
Copy link
Member

I added a fix to detect that Any CPU was correctly quoted.

@dbaeumer dbaeumer added the bug Issue identified by VS Code Team member as probable bug label May 22, 2018
@dbaeumer
Copy link
Member

To verify write a simple task that has a space in one of the args which is correctly quoted. Something like

		{
			"type": "shell",
			"label": "echo",
			"command": "echo",
			"args": [
				"dirk\" \"baeumer"
			],
			"problemMatcher": []
		}

The executed command should be echo dirk" "baeumer and not echo "dirk" "baeumer"

@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 6, 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
Projects
None yet
Development

No branches or pull requests

2 participants