Skip to content

Commit 2be5d61

Browse files
fix: allow paths in --exclude parameter for IaC commands while maintaining backwards compatibility
- Remove path separator validation only for IaC commands (--iac flag) - Keep existing validation for open source scanning to maintain backwards compatibility - Update tests to verify both behaviors work correctly - IaC commands now support: --exclude=path/to/dir, --exclude=subdir/file.tf - Open source commands still restrict to: --exclude=dirname, --exclude=filename Fixes issue where --exclude parameter only worked with single files and directories without path separators for IaC commands.
1 parent 92465fa commit 2be5d61

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/cli/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ function validateUnsupportedOptionCombinations(
443443
if (typeof options.exclude !== 'string') {
444444
throw new ExcludeFlagBadInputError();
445445
}
446-
if (options.exclude.indexOf(pathLib.sep) > -1) {
446+
// Only apply path separator validation for non-IaC commands to maintain backwards compatibility
447+
if (!options.iac && options.exclude.indexOf(pathLib.sep) > -1) {
447448
throw new ExcludeFlagInvalidInputError();
448449
}
449450
}

test/jest/acceptance/cli-args.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ describe('cli args', () => {
245245
expect(code).not.toEqual(2);
246246
});
247247

248-
test('snyk test --exclude=path/to/dir displays error message', async () => {
248+
test('snyk test --exclude=path/to/dir displays error message for open source', async () => {
249249
const exclude = path.normalize('path/to/dir');
250250
const { code, stdout } = await runSnykCLI(
251251
`test --all-projects --exclude=${exclude}`,
@@ -260,6 +260,23 @@ describe('cli args', () => {
260260
expect(code).toEqual(2);
261261
});
262262

263+
test('snyk iac test --exclude=path/to/dir should work with paths', async () => {
264+
const exclude = path.normalize('path/to/dir');
265+
const { code, stdout } = await runSnykCLI(
266+
`iac test --exclude=${exclude}`,
267+
{
268+
env,
269+
},
270+
);
271+
272+
// Should not display error message about paths not being allowed for IaC
273+
expect(stdout).not.toContainText(
274+
'The --exclude argument must be a comma separated list of directory or file names and cannot contain a path.',
275+
);
276+
// Should not fail with error code 2 due to path validation for IaC
277+
expect(code).not.toEqual(2);
278+
});
279+
263280
[
264281
'config',
265282
'ignore',

0 commit comments

Comments
 (0)