@leonardo-marziali/ad-lfl-kit 1.4.1 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exec.js +23 -4
- package/package.json +1 -1
package/exec.js
CHANGED
|
@@ -38,12 +38,31 @@ function resolveBin(name, options = {}) {
|
|
|
38
38
|
* argv when shell:true — so quote each argument here. Runs of backslashes
|
|
39
39
|
* before a quote (and at the very end) are doubled first, since cmd.exe would
|
|
40
40
|
* otherwise treat them as escaping the quote.
|
|
41
|
+
*
|
|
42
|
+
* A manual scan (rather than a `(\\*)"`-shaped regex) avoids the non-linear
|
|
43
|
+
* backtracking such a pattern hits on long, quote-free input: unanchored,
|
|
44
|
+
* it retries the greedy backslash run at every position in the string.
|
|
41
45
|
*/
|
|
42
46
|
function quoteForCmd(arg) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
const str = String(arg);
|
|
48
|
+
let result = '';
|
|
49
|
+
let backslashes = 0;
|
|
50
|
+
|
|
51
|
+
for (const ch of str) {
|
|
52
|
+
if (ch === '\\') {
|
|
53
|
+
backslashes += 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (ch === '"') {
|
|
57
|
+
result += '\\'.repeat(backslashes * 2) + '""';
|
|
58
|
+
} else {
|
|
59
|
+
result += '\\'.repeat(backslashes) + ch;
|
|
60
|
+
}
|
|
61
|
+
backslashes = 0;
|
|
62
|
+
}
|
|
63
|
+
result += '\\'.repeat(backslashes * 2);
|
|
64
|
+
|
|
65
|
+
return `"${result}"`;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
/*
|
package/package.json
CHANGED