Skip to content

Commit

Permalink
fix: quote windows command line arguments (#5808)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni authored Jul 30, 2024
1 parent efa3553 commit bf9a6cd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
20 changes: 14 additions & 6 deletions lib/base-package-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isInteractive } from "./common/helpers";
import { isInteractive, quoteString } from "./common/helpers";
import {
INodePackageManager,
INodePackageManagerInstallOptions,
Expand Down Expand Up @@ -108,11 +108,19 @@ export abstract class BasePackageManager implements INodePackageManager {
): Promise<INpmInstallResultInfo> {
const npmExecutable = this.getPackageManagerExecutableName();
const stdioValue = isInteractive() ? "inherit" : "pipe";
await this.$childProcess.spawnFromEvent(npmExecutable, params, "close", {
cwd: opts.cwd,
stdio: stdioValue,
shell: this.$hostInfo.isWindows,
});
const sanitizedNpmExecutable = this.$hostInfo.isWindows
? quoteString(npmExecutable)
: npmExecutable;
await this.$childProcess.spawnFromEvent(
sanitizedNpmExecutable,
params,
"close",
{
cwd: opts.cwd,
stdio: stdioValue,
shell: this.$hostInfo.isWindows,
}
);

// Whenever calling "npm install" or "yarn add" without any arguments (hence installing all dependencies) no output is emitted on stdout
// 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.
Expand Down
7 changes: 5 additions & 2 deletions lib/common/mobile/android/android-virtual-device-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NOT_RUNNING_EMULATOR_STATUS,
} from "../../constants";
import { cache } from "../../decorators";
import { settlePromises } from "../../helpers";
import { quoteString, settlePromises } from "../../helpers";
import { DeviceConnectionType } from "../../../constants";
import {
IStringDictionary,
Expand Down Expand Up @@ -221,8 +221,11 @@ export class AndroidVirtualDeviceService
}

if (canExecuteAvdManagerCommand) {
const sanitizedPathToAvdManagerExecutable = this.$hostInfo.isWindows
? quoteString(this.pathToAvdManagerExecutable)
: this.pathToAvdManagerExecutable;
result = await this.$childProcess.trySpawnFromCloseEvent(
this.pathToAvdManagerExecutable,
sanitizedPathToAvdManagerExecutable,
["list", "avds"],
{ shell: this.$hostInfo.isWindows }
);
Expand Down
7 changes: 5 additions & 2 deletions lib/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PLUGIN_BUILD_DATA_FILENAME,
SCOPED_ANDROID_RUNTIME_NAME,
} from "../constants";
import { getShortPluginName, hook } from "../common/helpers";
import { getShortPluginName, hook, quoteString } from "../common/helpers";
import { Builder, parseString } from "xml2js";
import {
IRuntimeGradleVersions,
Expand Down Expand Up @@ -841,9 +841,12 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
}

try {
const sanitizedArgs = this.$hostInfo.isWindows
? localArgs.map((arg) => quoteString(arg))
: localArgs;
await this.$childProcess.spawnFromEvent(
gradlew,
localArgs,
sanitizedArgs,
"close",
opts
);
Expand Down
6 changes: 5 additions & 1 deletion lib/services/android/gradle-command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IGradleCommandOptions,
} from "../../definitions/gradle";
import { injector } from "../../common/yok";
import { quoteString } from "../../common/helpers";

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

const sanitizedGradleArgs = this.$hostInfo.isWindows
? gradleArgs.map((arg) => quoteString(arg))
: gradleArgs;
const result = await this.executeCommandSafe(
gradleExecutable,
gradleArgs,
sanitizedGradleArgs,
childProcessOptions,
spawnOptions
);
Expand Down

0 comments on commit bf9a6cd

Please sign in to comment.