Skip to content

Commit b88eda5

Browse files
Copiloticlanton
andcommitted
fix(heft-jest-plugin): Add bounds checks for argument parsing
Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
1 parent 1bbe41a commit b88eda5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

heft-plugins/heft-jest-plugin/src/heft-jest-cli.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ function parseJestArgsToHeft(args: string[]): IHeftJestArgs {
161161

162162
// Handle --outputFile (skip with its value)
163163
if (arg === '--outputFile') {
164-
// Skip this and the next argument (the file path)
165-
i += 2;
164+
// Skip this and the next argument (the file path) if it exists
165+
if (i + 1 < args.length) {
166+
i += 2;
167+
} else {
168+
i++;
169+
}
166170
continue;
167171
}
168172
if (arg.startsWith('--outputFile=')) {
@@ -172,8 +176,12 @@ function parseJestArgsToHeft(args: string[]): IHeftJestArgs {
172176

173177
// Handle --reporters (skip with its value)
174178
if (arg === '--reporters') {
175-
// Skip this and the next argument (the reporter)
176-
i += 2;
179+
// Skip this and the next argument (the reporter) if it exists
180+
if (i + 1 < args.length) {
181+
i += 2;
182+
} else {
183+
i++;
184+
}
177185
continue;
178186
}
179187
if (arg.startsWith('--reporters=')) {
@@ -183,7 +191,12 @@ function parseJestArgsToHeft(args: string[]): IHeftJestArgs {
183191

184192
// Handle --config (skip with its value as Heft has its own config handling)
185193
if (arg === '--config' || arg === '-c') {
186-
i += 2;
194+
// Skip this and the next argument (the config path) if it exists
195+
if (i + 1 < args.length) {
196+
i += 2;
197+
} else {
198+
i++;
199+
}
187200
continue;
188201
}
189202
if (arg.startsWith('--config=')) {

0 commit comments

Comments
 (0)