MCPcopy Index your code
hub / github.com/nodejs/node / escapePOSIXShell

Function escapePOSIXShell

test/common/index.js:910–925  ·  view source on GitHub ↗

* Escape values in a string template literal. On Windows, this function * does not escape anything (which is fine for paths, as `"` is not a valid char * in a path on Windows), so you should use it only to escape paths – or other * values on tests which are skipped on Windows. * This function is

(cmdParts, ...args)

Source from the content-addressed store, hash-verified

908 * arguments to `exec` or `execSync`.
909 */
910function escapePOSIXShell(cmdParts, ...args) {
911 if (common.isWindows) {
912 // On Windows, paths cannot contain `"`, so we can return the string unchanged.
913 return [String.raw({ raw: cmdParts }, ...args)];
914 }
915 // On POSIX shells, we can pass values via the env, as there's a standard way for referencing a variable.
916 const env = { ...process.env };
917 let cmd = cmdParts[0];
918 for (let i = 0; i < args.length; i++) {
919 const envVarName = `ESCAPED_${i}`;
920 env[envVarName] = args[i];
921 cmd += '${' + envVarName + '}' + cmdParts[i + 1];
922 }
923
924 return [cmd, { env }];
925};
926
927/**
928 * Check the exports of require(esm).

Callers 3

childShouldThrowAndAbortFunction · 0.85
rmSyncFunction · 0.85

Calls 1

rawMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…