Skip to content

Commit a27eec1

Browse files
wip testing
1 parent 403a216 commit a27eec1

File tree

8 files changed

+604
-48
lines changed

8 files changed

+604
-48
lines changed

src/internal/tmp.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function chain({ escape, flagProtect, quote }) {
2+
return quote(flagProtect(escape(arg)));
3+
}
4+
5+
export function id(arg) {
6+
return arg;
7+
}

src/internal/win/cmd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ export function getQuoteFunction() {
7070
* @returns {function(string): string} A function to protect against flag injection.
7171
*/
7272
export function getFlagProtectionFunction() {
73-
const leadingHyphensAndSlashes = new RegExp(/^(?:-+|\/+)/);
73+
const leadingHyphensAndSlashes = new RegExp(/^(?:-|\/)+/);
7474
return (arg) => arg.replace(leadingHyphensAndSlashes, "");
7575
}

src/internal/win/no-shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ export function getQuoteFunction() {
4949
* @returns {function(string): string} A function to protect against flag injection.
5050
*/
5151
export function getFlagProtectionFunction() {
52-
const leadingHyphensAndSlashes = new RegExp(/^(?:-+|\/+)/);
52+
const leadingHyphensAndSlashes = new RegExp(/^(?:-|\/)+/);
5353
return (arg) => arg.replace(leadingHyphensAndSlashes, "");
5454
}

src/internal/win/powershell.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export function getEscapeFunction() {
1616
const newlines = new RegExp(/\n/g);
1717
const backticks = new RegExp(/`/g);
1818
const redirects = new RegExp(/(^|[\s\u0085])([*1-6]?)(>)/g);
19-
const hyphens = new RegExp(/([\s\u0085])-/g);
2019
const specials1 = new RegExp(/(^|[\s\u0085])([#\-:<@\]])/g);
2120
const specials2 = new RegExp(/([$&'(),;{|}])/g);
2221

@@ -34,7 +33,6 @@ export function getEscapeFunction() {
3433
.replace(newlines, " ")
3534
.replace(backticks, "``")
3635
.replace(redirects, "$1$2`$3")
37-
.replace(hyphens, "$1`-")
3836
.replace(specials1, "$1`$2")
3937
.replace(specials2, "`$1");
4038

@@ -114,6 +112,6 @@ export function getQuoteFunction() {
114112
* @returns {function(string): string} A function to protect against flag injection.
115113
*/
116114
export function getFlagProtectionFunction() {
117-
const leadingHyphensAndSlashes = new RegExp(/^(?:-+|\/+)/);
115+
const leadingHyphensAndSlashes = new RegExp(/^(?:-|\/)+/);
118116
return (arg) => arg.replace(leadingHyphensAndSlashes, "");
119117
}

temp.js

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,43 @@
1-
import { exec } from "node:child_process";
1+
import { execSync } from "node:child_process";
22
import { Shescape } from "shescape";
33

44
const options = { shell: "powershell" };
55
const shescape = new Shescape({ shell: "powershell" });
66

7-
exec(`gh ${shescape.escape("--help")}`, options, (error) => {
8-
if (error) {
9-
console.log("gh --help : error");
10-
} else {
11-
console.log("gh --help : no error");
12-
}
13-
});
14-
exec(`gh ${shescape.escape("`--help")}`, options, (error) => {
15-
if (error) {
16-
console.log("gh `--help : error");
17-
} else {
18-
console.log("gh `--help : no error");
19-
}
20-
});
21-
exec(`gh ${shescape.escape("``--help")}`, options, options, (error) => {
22-
if (error) {
23-
console.log("gh ``--help : error");
24-
} else {
25-
console.log("gh ``--help : no error");
26-
}
27-
});
7+
try {
8+
execSync(`gh ${shescape.escape("--help")}`, options);
9+
console.log("gh --help : no error");
10+
} catch {
11+
console.log("gh --help : error");
12+
}
13+
try {
14+
execSync(`gh ${shescape.escape("`--help")}`, options);
15+
console.log("gh `--help : no error");
16+
} catch {
17+
console.log("gh `--help : error");
18+
}
19+
try {
20+
execSync(`gh ${shescape.escape("``--help")}`, options, options);
21+
console.log("gh ``--help : no error");
22+
} catch {
23+
console.log("gh ``--help : error");
24+
}
2825

29-
exec(`gh ${shescape.quote("--help")}`, options, (error) => {
30-
if (error) {
31-
console.log("gh '--help': error");
32-
} else {
33-
console.log("gh '--help': no error");
34-
}
35-
});
36-
exec(`gh ${shescape.quote("`--help")}`, options, (error) => {
37-
if (error) {
38-
console.log("gh '`--help': error");
39-
} else {
40-
console.log("gh '`--help': no error");
41-
}
42-
});
43-
exec(`gh ${shescape.quote("``--help")}`, options, (error) => {
44-
if (error) {
45-
console.log("gh '``--help': error");
46-
} else {
47-
console.log("gh '``--help': no error");
48-
}
49-
});
26+
try {
27+
execSync(`gh ${shescape.quote("--help")}`, options);
28+
console.log("gh '--help': no error");
29+
} catch {
30+
console.log("gh '--help': error");
31+
}
32+
try {
33+
execSync(`gh ${shescape.quote("`--help")}`, options);
34+
console.log("gh '`--help': no error");
35+
} catch {
36+
console.log("gh '`--help': error");
37+
}
38+
try {
39+
execSync(`gh ${shescape.quote("``--help")}`, options);
40+
console.log("gh '``--help': no error");
41+
} catch {
42+
console.log("gh '``--help': error");
43+
}

0 commit comments

Comments
 (0)