Skip to content

Commit

Permalink
Update quoting for CMD to ... not quote(?)
Browse files Browse the repository at this point in the history
This commit is a work in progress...

CMD quoting is weird - It appears to be necessary to preserve whitespace
but you can't disable variable expansion from within quotes (evidenced
by the removal of `_common.cjs` line 68 to 70).

The main progress of this commit is that it fixes the incorrect escaping
of `%` when quoting for CMD. However, it lacks whitespace preservation
which should really be kept - and, to reiterate, whitespace preservation
is impossible without quoting in CMD, as far as I'm aware.
  • Loading branch information
ericcornelissen committed Jun 21, 2023
1 parent 8323dd3 commit 69275eb
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 139 deletions.
18 changes: 2 additions & 16 deletions src/win/cmd.js
Expand Up @@ -43,28 +43,14 @@ export function getEscapeFunction(options) {
}
}

/**
* Escape an argument for use in CMD when the argument is being quoted.
*
* @param {string} arg The argument to escape.
* @returns {string} The escaped argument.
*/
function escapeArgForQuoted(arg) {
return arg
.replace(/[\0\u0008\u001B\u009B]/gu, "")
.replace(/\r?\n|\r/gu, " ")
.replace(/%/gu, "^%")
.replace(/"/gu, `""`);
}

/**
* Quotes an argument for use in CMD.
*
* @param {string} arg The argument to quote.
* @returns {string} The quoted argument.
*/
function quoteArg(arg) {
return `"${arg}"`;
return `${arg}`;
}

/**
Expand All @@ -73,7 +59,7 @@ function quoteArg(arg) {
* @returns {Function[]} A function pair to escape & quote arguments.
*/
export function getQuoteFunction() {
return [escapeArgForQuoted, quoteArg];
return [escapeArgForInterpolation, quoteArg];
}

/**
Expand Down

0 comments on commit 69275eb

Please sign in to comment.