Skip to content

Commit 1952488

Browse files
committed
fix: cover ruby perl eval clusters
1 parent 9db8060 commit 1952488

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/infra/command-analysis/inline-eval.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,23 @@ describe("exec inline eval detection", () => {
3636
{ argv: ["ruby", "-p00e", "puts 1"], expected: "ruby -e" },
3737
{ argv: ["ruby", "-pe", "puts 1"], expected: "ruby -e" },
3838
{ argv: ["ruby", "-Se", "puts 1"], expected: "ruby -e" },
39+
{ argv: ["ruby", "-We", "puts 1"], expected: "ruby -e" },
40+
{ argv: ["ruby", "-W2e", "puts 1"], expected: "ruby -e" },
3941
{ argv: ["ruby", "-ve", "puts 1"], expected: "ruby -e" },
4042
{ argv: ["ruby", "-we", "puts 1"], expected: "ruby -e" },
4143
{ argv: ["perl", "-E", "say 1"], expected: "perl -e" },
4244
{ argv: ["perl", "-Esay 1"], expected: "perl -e" },
4345
{ argv: ["perl", "-ce", "say 1"], expected: "perl -e" },
46+
{ argv: ["perl", "-de", "say 1"], expected: "perl -e" },
4447
{ argv: ["perl", "-fe", "say 1"], expected: "perl -e" },
48+
{ argv: ["perl", "-l0e", "say 1"], expected: "perl -e" },
4549
{ argv: ["perl", "-ne", "say 1"], expected: "perl -e" },
4650
{ argv: ["perl", "-0777pe", "say 1"], expected: "perl -e" },
4751
{ argv: ["perl", "-p0777e", "say 1"], expected: "perl -e" },
4852
{ argv: ["perl", "-Se", "say 1"], expected: "perl -e" },
53+
{ argv: ["perl", "-Te", "say 1"], expected: "perl -e" },
54+
{ argv: ["perl", "-UE", "say 1"], expected: "perl -e" },
55+
{ argv: ["perl", "-Ve", "say 1"], expected: "perl -e" },
4956
{ argv: ["perl", "-We", "say 1"], expected: "perl -e" },
5057
{ argv: ["perl", "-we", "say 1"], expected: "perl -e" },
5158
{ argv: ["perl", "-Xe", "say 1"], expected: "perl -e" },
@@ -104,7 +111,12 @@ describe("exec inline eval detection", () => {
104111
expect(detectInterpreterInlineEvalArgv(["find", ".", "-execute", "id"])).toBeNull();
105112
expect(detectInterpreterInlineEvalArgv(["ruby", "-EUTF-8", "script.rb"])).toBeNull();
106113
expect(detectInterpreterInlineEvalArgv(["ruby", "-Itest", "script.rb"])).toBeNull();
114+
expect(detectInterpreterInlineEvalArgv(["ruby", "-W:deprecatede", "puts 1"])).toBeNull();
107115
expect(detectInterpreterInlineEvalArgv(["ruby", "-7pe", "puts 1"])).toBeNull();
116+
expect(detectInterpreterInlineEvalArgv(["perl", "-C0e", "say 1"])).toBeNull();
117+
expect(detectInterpreterInlineEvalArgv(["perl", "-D0e", "say 1"])).toBeNull();
118+
expect(detectInterpreterInlineEvalArgv(["perl", "-me", "say 1"])).toBeNull();
119+
expect(detectInterpreterInlineEvalArgv(["perl", "-Me", "say 1"])).toBeNull();
108120
expect(detectInterpreterInlineEvalArgv(["perl", "-7pe", "say 1"])).toBeNull();
109121
expect(detectInterpreterInlineEvalArgv(["perl", "-0xFFpe", "say 1"])).toBeNull();
110122
expect(detectInterpreterInlineEvalArgv(["php", "-F", "filter.php"])).toBeNull();

src/infra/command-analysis/inline-eval.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type ShortClusterFlagSpec = {
3030
flag: string;
3131
prefixChars: ReadonlySet<string>;
3232
allowNumericRecordSeparator?: boolean;
33+
numericValuePrefixChars?: ReadonlySet<string>;
3334
};
3435

3536
type PositionalInterpreterSpec = {
@@ -88,8 +89,9 @@ const FLAG_INTERPRETER_INLINE_EVAL_SPECS: readonly InterpreterFlagSpec[] = [
8889
{
8990
label: "-e",
9091
flag: "e",
91-
prefixChars: new Set(["S", "U", "a", "c", "d", "l", "n", "p", "s", "v", "w"]),
92+
prefixChars: new Set(["S", "U", "W", "a", "c", "d", "l", "n", "p", "s", "v", "w"]),
9293
allowNumericRecordSeparator: true,
94+
numericValuePrefixChars: new Set(["W"]),
9395
},
9496
],
9597
},
@@ -105,8 +107,11 @@ const FLAG_INTERPRETER_INLINE_EVAL_SPECS: readonly InterpreterFlagSpec[] = [
105107
"T",
106108
"W",
107109
"X",
110+
"U",
111+
"V",
108112
"a",
109113
"c",
114+
"d",
110115
"f",
111116
"l",
112117
"n",
@@ -117,6 +122,7 @@ const FLAG_INTERPRETER_INLINE_EVAL_SPECS: readonly InterpreterFlagSpec[] = [
117122
"w",
118123
]),
119124
allowNumericRecordSeparator: true,
125+
numericValuePrefixChars: new Set(["l"]),
120126
},
121127
{
122128
label: "-e",
@@ -126,8 +132,11 @@ const FLAG_INTERPRETER_INLINE_EVAL_SPECS: readonly InterpreterFlagSpec[] = [
126132
"T",
127133
"W",
128134
"X",
135+
"U",
136+
"V",
129137
"a",
130138
"c",
139+
"d",
131140
"f",
132141
"l",
133142
"n",
@@ -138,6 +147,7 @@ const FLAG_INTERPRETER_INLINE_EVAL_SPECS: readonly InterpreterFlagSpec[] = [
138147
"w",
139148
]),
140149
allowNumericRecordSeparator: true,
150+
numericValuePrefixChars: new Set(["l"]),
141151
},
142152
],
143153
},
@@ -358,6 +368,11 @@ function isShortClusterPrefixAllowed(clusterFlag: ShortClusterFlagSpec, prefix:
358368
for (let index = 0; index < prefix.length; index += 1) {
359369
const char = prefix[index] ?? "";
360370
if (clusterFlag.prefixChars.has(char)) {
371+
if (clusterFlag.numericValuePrefixChars?.has(char) === true) {
372+
while (/^[0-9]$/.test(prefix[index + 1] ?? "")) {
373+
index += 1;
374+
}
375+
}
361376
continue;
362377
}
363378
if (clusterFlag.allowNumericRecordSeparator === true && char === "0") {

0 commit comments

Comments
 (0)