Skip to content

Commit 14b274a

Browse files
committed
fixup! test: add escapePathsFromShellCommand util
1 parent c998f9c commit 14b274a

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

test/common/index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -953,26 +953,21 @@ function expectRequiredModule(mod, expectation, checkESModule = true) {
953953
* @returns {[string, object | undefined]} An array that can be passed as
954954
* arguments to `exec` or `execSync`.
955955
*/
956-
function escapePathsFromShellCommand(cmdParts, ...args) {
956+
function escapePOSIXShell(cmdParts, ...args) {
957957
if (common.isWindows) {
958958
// On Windows, paths cannot contain `"`, so we can return the string unchanged.
959959
return [String.raw({ raw: cmdParts }, ...args)];
960960
}
961961
// On POSIX shells, we can pass values via the env, as there's a standard way for referencing a variable.
962-
const env = {...process.env}
962+
const env = { ...process.env };
963963
let cmd = cmdParts[0];
964964
for (let i = 0; i < args.length; i++) {
965-
if (cmdParts[i].at(-1) === '"' && cmdParts[i + 1][0] === '"') {
966-
const envVarName = `ESCAPED_${i}`
967-
cmd += '$' + envVarName;
968-
env[envVarName] = args[i];
969-
} else {
970-
cmd += args[i];
971-
}
972-
cmd += cmdParts[i + 1]
965+
const envVarName = `ESCAPED_${i}`;
966+
env[envVarName] = args[i];
967+
cmd += '${' + envVarName + '}' + cmdParts[i + 1];
973968
}
974969

975-
return [cmd, { env }]
970+
return [cmd, { env }];
976971
}
977972

978973
const common = {
@@ -982,7 +977,7 @@ const common = {
982977
childShouldThrowAndAbort,
983978
createZeroFilledFile,
984979
defaultAutoSelectFamilyAttemptTimeout,
985-
escapePathsFromShellCommand,
980+
escapePOSIXShell,
986981
expectsError,
987982
expectRequiredModule,
988983
expectWarning,

test/sequential/test-cli-syntax-good.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { escapePathsFromShellCommand } = require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const { exec } = require('child_process');
66
const fixtures = require('../common/fixtures');
@@ -24,7 +24,7 @@ const syntaxArgs = [
2424

2525
// Loop each possible option, `-c` or `--check`
2626
syntaxArgs.forEach(function(flag) {
27-
exec(...escapePathsFromShellCommand`"${process.execPath}" ${flag} "${file}"`, common.mustCall((err, stdout, stderr) => {
27+
exec(...common.escapePOSIXShell`"${process.execPath}" ${flag} "${file}"`, common.mustCall((err, stdout, stderr) => {
2828
if (err) {
2929
console.log('-- stdout --');
3030
console.log(stdout);

0 commit comments

Comments
 (0)