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

fix(aws-cdk): escape spaces while invoking dotnet command #18957

Closed

Conversation

bhargav50
Copy link

When dotnet command is invoked, if arguments are given with spaces unescaped, it interprets that as the start of the second command.

In this case, when csharp project is initialized, dotnet sln command is invoked with slnPath and fsprojPath.

Spaces in slnPath and fsprojPath should be escaped before providing them as arguments to the dotnet command

Fixes #18803


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

When dotnet command is invoked, if arguments are given
with spaces unescaped, it interprets that as the start
of second command.

In this case, when csharp project is initialized,
`dotnet sln` command is invoked with slnPath and fsprojPath.

Spaces in `slnPath` and `fsprojPath` should be escaped
before providing them as argument to dotnet command

Fixes aws#18803

----

*By submitting this pull request, I confirm that my contribution is made under the terms of t
he Apache-2.0 license*
@gitpod-io
Copy link

gitpod-io bot commented Feb 12, 2022

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 6ad8ea6
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@@ -3,10 +3,13 @@ import * as path from 'path';
import { InvokeHook } from '../../../../init';

export const invoke: InvokeHook = async (targetDirectory: string) => {
const escapeSpaces = (value: string) => {
return value.replace(' ', '\\ ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also work on Windows? I'm pretty sure that if you put a \ in a command line on Windows, it is just interpreted as a literal \, not as escaping the next character.

const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln');
const csprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.csproj');

const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', csprojPath], {
const child = child_process.spawn('dotnet', ['sln', escapeSpaces(slnPath), 'add', escapeSpaces(csprojPath)], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that child_process.spawn doesn't add quotes around the arguments in the first place. I don't understand what the point of the argument array is without doing that.

Can you find documentation on the internet around this behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use this function instead:

export async function shell(command: string[], options: ShellOptions = {}): Promise<string> {

@github-actions
Copy link

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@github-actions
Copy link

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@github-actions github-actions bot added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Apr 28, 2022
@github-actions github-actions bot closed this Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdk init app: space causes failure
3 participants