Skip to content

Commit bf9a6cd

Browse files
authored
fix: quote windows command line arguments (#5808)
1 parent efa3553 commit bf9a6cd

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

lib/base-package-manager.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isInteractive } from "./common/helpers";
1+
import { isInteractive, quoteString } from "./common/helpers";
22
import {
33
INodePackageManager,
44
INodePackageManagerInstallOptions,
@@ -108,11 +108,19 @@ export abstract class BasePackageManager implements INodePackageManager {
108108
): Promise<INpmInstallResultInfo> {
109109
const npmExecutable = this.getPackageManagerExecutableName();
110110
const stdioValue = isInteractive() ? "inherit" : "pipe";
111-
await this.$childProcess.spawnFromEvent(npmExecutable, params, "close", {
112-
cwd: opts.cwd,
113-
stdio: stdioValue,
114-
shell: this.$hostInfo.isWindows,
115-
});
111+
const sanitizedNpmExecutable = this.$hostInfo.isWindows
112+
? quoteString(npmExecutable)
113+
: npmExecutable;
114+
await this.$childProcess.spawnFromEvent(
115+
sanitizedNpmExecutable,
116+
params,
117+
"close",
118+
{
119+
cwd: opts.cwd,
120+
stdio: stdioValue,
121+
shell: this.$hostInfo.isWindows,
122+
}
123+
);
116124

117125
// Whenever calling "npm install" or "yarn add" without any arguments (hence installing all dependencies) no output is emitted on stdout
118126
// Luckily, whenever you call "npm install" or "yarn add" to install all dependencies chances are you won't need the name/version of the package you're installing because there is none.

lib/common/mobile/android/android-virtual-device-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
NOT_RUNNING_EMULATOR_STATUS,
1010
} from "../../constants";
1111
import { cache } from "../../decorators";
12-
import { settlePromises } from "../../helpers";
12+
import { quoteString, settlePromises } from "../../helpers";
1313
import { DeviceConnectionType } from "../../../constants";
1414
import {
1515
IStringDictionary,
@@ -221,8 +221,11 @@ export class AndroidVirtualDeviceService
221221
}
222222

223223
if (canExecuteAvdManagerCommand) {
224+
const sanitizedPathToAvdManagerExecutable = this.$hostInfo.isWindows
225+
? quoteString(this.pathToAvdManagerExecutable)
226+
: this.pathToAvdManagerExecutable;
224227
result = await this.$childProcess.trySpawnFromCloseEvent(
225-
this.pathToAvdManagerExecutable,
228+
sanitizedPathToAvdManagerExecutable,
226229
["list", "avds"],
227230
{ shell: this.$hostInfo.isWindows }
228231
);

lib/services/android-plugin-build-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
PLUGIN_BUILD_DATA_FILENAME,
99
SCOPED_ANDROID_RUNTIME_NAME,
1010
} from "../constants";
11-
import { getShortPluginName, hook } from "../common/helpers";
11+
import { getShortPluginName, hook, quoteString } from "../common/helpers";
1212
import { Builder, parseString } from "xml2js";
1313
import {
1414
IRuntimeGradleVersions,
@@ -841,9 +841,12 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
841841
}
842842

843843
try {
844+
const sanitizedArgs = this.$hostInfo.isWindows
845+
? localArgs.map((arg) => quoteString(arg))
846+
: localArgs;
844847
await this.$childProcess.spawnFromEvent(
845848
gradlew,
846-
localArgs,
849+
sanitizedArgs,
847850
"close",
848851
opts
849852
);

lib/services/android/gradle-command-service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
IGradleCommandOptions,
1111
} from "../../definitions/gradle";
1212
import { injector } from "../../common/yok";
13+
import { quoteString } from "../../common/helpers";
1314

1415
export class GradleCommandService implements IGradleCommandService {
1516
constructor(
@@ -35,9 +36,12 @@ export class GradleCommandService implements IGradleCommandService {
3536
options.gradlePath ??
3637
(this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew");
3738

39+
const sanitizedGradleArgs = this.$hostInfo.isWindows
40+
? gradleArgs.map((arg) => quoteString(arg))
41+
: gradleArgs;
3842
const result = await this.executeCommandSafe(
3943
gradleExecutable,
40-
gradleArgs,
44+
sanitizedGradleArgs,
4145
childProcessOptions,
4246
spawnOptions
4347
);

0 commit comments

Comments
 (0)