Skip to content

Commit 65f0c48

Browse files
authored
fix(dotnet): update handling of extraParameters to be compatible with spawn (#403)
1 parent 84bde4c commit 65f0c48

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

packages/dotnet/.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { DotNetClient } from './dotnet.client';
2+
import { mockDotnetFactory } from './dotnet.factory';
3+
import * as cp from 'child_process';
4+
5+
describe('dotnet client', () => {
6+
describe('publish', () => {
7+
describe('extra parameters', () => {
8+
const dotnetClient = new DotNetClient(mockDotnetFactory());
9+
10+
let spawnSyncSpy: jest.SpyInstance;
11+
12+
beforeEach(() => {
13+
spawnSyncSpy = jest
14+
.spyOn(cp, 'spawnSync')
15+
.mockImplementation(jest.fn());
16+
});
17+
18+
afterEach(() => {
19+
jest.resetAllMocks();
20+
});
21+
22+
it('should handle multiple parameters', () => {
23+
dotnetClient.publish(
24+
'my-project',
25+
undefined,
26+
undefined,
27+
'--flag --other-flag',
28+
);
29+
expect(spawnSyncSpy.mock.calls[0][1]).toContain('--flag');
30+
expect(spawnSyncSpy.mock.calls[0][1]).toContain('--other-flag');
31+
expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
32+
});
33+
34+
it('should handle multiple parameters with quotations', () => {
35+
dotnetClient.publish(
36+
'my-project',
37+
undefined,
38+
undefined,
39+
`--flag \\p:"my project"`,
40+
);
41+
expect(spawnSyncSpy.mock.calls[0][1]).toContain('--flag');
42+
expect(spawnSyncSpy.mock.calls[0][1]).toContain('\\p:"my project"');
43+
expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
44+
});
45+
46+
it('should handle several parameters', () => {
47+
dotnetClient.publish(
48+
'my-project',
49+
undefined,
50+
undefined,
51+
`--self-contained=false /p:CopyOutputSymbolsToPublishDirectory=false /p:Version=2022.03.25.1 /p:VersionAssembly=2022.03.25.1 /p:Name:"My Project"`,
52+
);
53+
expect(spawnSyncSpy.mock.calls[0][1]).toMatchInlineSnapshot(`
54+
Array [
55+
"publish",
56+
"\\"my-project\\"",
57+
"--self-contained=false",
58+
"/p:CopyOutputSymbolsToPublishDirectory=false",
59+
"/p:Version=2022.03.25.1",
60+
"/p:VersionAssembly=2022.03.25.1",
61+
"/p:Name:\\"My Project\\"",
62+
]
63+
`);
64+
expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
65+
});
66+
});
67+
});
68+
});

packages/dotnet/src/lib/core/dotnet.client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export class DotNetClient {
110110
params.push(`-p:PublishProfile=${publishProfile}`);
111111
}
112112
if (extraParameters) {
113-
params.push(`${extraParameters}`);
113+
const matches = extraParameters.match(EXTRA_PARAMS_REGEX);
114+
params.push(...(matches as RegExpMatchArray));
114115
}
115116
return this.logAndExecute(params);
116117
}
@@ -195,3 +196,10 @@ export class DotNetClient {
195196
});
196197
}
197198
}
199+
200+
/**
201+
* Regular Expression for Parsing Extra Params before sending to spawn / exec
202+
* First part of expression matches parameters such as --flag="my answer"
203+
* Second part of expression matches parameters such as --flag=my_answer
204+
*/
205+
const EXTRA_PARAMS_REGEX = /\S*".+?"|\S+/g;

0 commit comments

Comments
 (0)