Skip to content

Commit

Permalink
fix(core): improve quoting args in running integration test jobs
Browse files Browse the repository at this point in the history
Reviewed By: tulga1970

Differential Revision: D57249292

fbshipit-source-id: 4f24c20269217a13230e09f6f9f6225077556c6e
  • Loading branch information
JacksonGL authored and facebook-github-bot committed May 13, 2024
1 parent c360a62 commit eebc764
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/lib/ProcessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {Command, Optional} from './Types';
import info from './Console';
import cp from 'child_process';
import os from 'os';
import utils from './Utils';

type Options = {
msg?: string;
Expand Down Expand Up @@ -66,7 +67,7 @@ class ProcessManager {
if (options.msg) {
info.lowLevel(options.msg);
}
const str = [cmd, ...args].join(' ');
const str = utils.convertCLIArgsToReadableCommand([cmd, ...args]);
this.nProc++;
const proc = cp.spawn(cmd, args);
proc.on('exit', code => {
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/lib/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,22 @@ function setChromiumBinary(config: MemLabConfig, chromiumBinary: string) {
config.puppeteerConfig.executablePath = binaryPath;
}

function convertToReadableArg(arg: string): string {
const startsWithBackslashAndQuote = arg.startsWith('\\"');
const endsWithBackslashAndQuote = arg.endsWith('\\"');
if (startsWithBackslashAndQuote && endsWithBackslashAndQuote) {
return `"${arg.substring(2, arg.length - 2)}"`;
}
if (/\s/.test(arg)) {
return `"${arg}"`;
}
return arg;
}

function convertCLIArgsToReadableCommand(args: string[]): string {
return args.map(convertToReadableArg).join(' ');
}

export default {
aggregateDominatorMetrics,
applyToNodes,
Expand All @@ -2150,6 +2166,7 @@ export default {
checkSnapshots,
checkUninstalledLibrary,
closePuppeteer,
convertCLIArgsToReadableCommand,
dumpSnapshot,
equalOrMatch,
extractClosureNodeInfo,
Expand Down

0 comments on commit eebc764

Please sign in to comment.