diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index 0ba57c37bf..44265cddd8 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to the Imperative package will be documented in this file. +## Recent Changes + +- BugFix: Fixed a typo in the syntax validation code for positional arguments which caused the validation to never fail. [#2375](https://github.com/zowe/zowe-cli/issues/2375) ## `8.10.1` diff --git a/packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts b/packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts index ea0b0be56b..b95dad3974 100644 --- a/packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts +++ b/packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts @@ -226,7 +226,7 @@ export class SyntaxValidator { if (!(commandArguments[positional.name] == null)) { if (positional.regex) { if (commandArguments[positional.name] - .toString().match(new RegExp(positional.regex) == null)) { + .toString().match(new RegExp(positional.regex)) == null) { valid = false; this.positionalParameterInvalid(positional, commandArguments[positional.name], responseObject); diff --git a/packages/imperative/src/cmd/src/syntax/__tests__/SyntaxValidator.unit.test.ts b/packages/imperative/src/cmd/src/syntax/__tests__/SyntaxValidator.unit.test.ts index 58bf12a29c..76759b6b51 100644 --- a/packages/imperative/src/cmd/src/syntax/__tests__/SyntaxValidator.unit.test.ts +++ b/packages/imperative/src/cmd/src/syntax/__tests__/SyntaxValidator.unit.test.ts @@ -525,6 +525,19 @@ describe("Imperative should provide advanced syntax validation rules", () => { expect(svResponse.valid).toEqual(true); }); + it("should fail if a positional argument does not match the defined regex", async () => { + const invalidPositional = "invalid_value"; + const regexForPositional = "^[a-zA-Z0-9_]+$"; + + return tryOptions.bind( + this, + `${minValidOptions} ${invalidPositional}`, + false, + [`Positional argument '${invalidPositional}' does not match the regex: ${regexForPositional}`] + )(); + }); + + describe("We should be able to validate positional arguments of type 'number'", () => { const numberCommand: ICommandDefinition = { name: "gimme-number", aliases: [],