Skip to content

Commit

Permalink
fix(aws-cdk): escape spaces while invoking dotnet command
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
bhargav50 committed Feb 12, 2022
1 parent ea7802b commit 9bc45d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ', '\\ ');
};
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)], {
// Need this for Windows where we want .cmd and .bat to be found as well.
shell: true,
stdio: ['ignore', 'pipe', 'inherit'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ', '\\ ');
};
const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln');
const fsprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.fsproj');

const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', fsprojPath], {
const child = child_process.spawn('dotnet', ['sln', escapeSpaces(slnPath), 'add', escapeSpaces(fsprojPath)], {
// Need this for Windows where we want .cmd and .bat to be found as well.
shell: true,
stdio: ['ignore', 'pipe', 'inherit'],
Expand Down

0 comments on commit 9bc45d6

Please sign in to comment.