-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
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*
AWS CodeBuild CI Report
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(' ', '\\ '); |
There was a problem hiding this comment.
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)], { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
aws-cdk/packages/aws-cdk/lib/os.ts
Line 15 in 3d71e44
export async function shell(command: string[], options: ShellOptions = {}): Promise<string> { |
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. |
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. |
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 withslnPath
andfsprojPath
.Spaces in
slnPath
andfsprojPath
should be escaped before providing them as arguments to thedotnet
commandFixes #18803
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license