From beff3d6a1fdf099b31c1721808f2c7f2c63568ff Mon Sep 17 00:00:00 2001 From: MAVRICK-1 Date: Thu, 12 Dec 2024 01:19:24 +0530 Subject: [PATCH 1/5] fix: correct regex match condition in SyntaxValidator Signed-off-by: MAVRICK-1 --- packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts b/packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts index ea0b0be56..b95dad397 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); From 4b477da8dd4a2dac6f1d23e65fc732cbd3afa4d4 Mon Sep 17 00:00:00 2001 From: MAVRICK-1 Date: Sat, 14 Dec 2024 00:35:35 +0530 Subject: [PATCH 2/5] changelog: update for version 8.8.4 with bug fix and enhancement for positional argument validation test: add unit test for invalid positional argument regex validation Signed-off-by: MAVRICK-1 --- packages/imperative/CHANGELOG.md | 5 +++++ .../syntax/__tests__/SyntaxValidator.unit.test.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index ded21b7c8..3331852dc 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the Imperative package will be documented in this file. +## `8.8.4` + +- BugFix: Broken validation of positional arguments. [#2384](https://github.com/zowe/zowe-cli/pull/2384) +- Enhancement: Added a test to validate it . [#2384](https://github.com/zowe/zowe-cli/pull/2384) + ## `8.8.3` - BugFix: Modified 8.8.2 bugfix to correct web help alias. [#2361](https://github.com/zowe/zowe-cli/pull/2361) 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 58bf12a29..92f8c7437 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.only("If a positional argument does not match the defined regex, the command should fail", 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: [], From 2850f3b18e4ef99b8343746e103ad4ecdea9fee2 Mon Sep 17 00:00:00 2001 From: MAVRICK-1 Date: Fri, 20 Dec 2024 03:28:31 +0530 Subject: [PATCH 3/5] Fix typo in syntax validation for positional arguments and add regression test Signed-off-by: MAVRICK-1 --- packages/imperative/CHANGELOG.md | 5 +++++ .../cmd/src/syntax/__tests__/SyntaxValidator.unit.test.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index 0ba57c37b..14224c398 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the Imperative package will be documented in this file. +## `8.10.2` + +- bugfix: fixed a typo in the syntax validation code for positional arguments. the bug caused the validation to never fail. [#2384](https://github.com/zowe/zowe-cli/pull/2384) +- enhancement: added a regression test to validate the fix. [#2384](https://github.com/zowe/zowe-cli/pull/2384) + (note: non-user-facing items like regression tests are typically not included in the changelog). ## `8.10.1` 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 92f8c7437..76759b6b5 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,7 +525,7 @@ describe("Imperative should provide advanced syntax validation rules", () => { expect(svResponse.valid).toEqual(true); }); - it.only("If a positional argument does not match the defined regex, the command should fail", async () => { + it("should fail if a positional argument does not match the defined regex", async () => { const invalidPositional = "invalid_value"; const regexForPositional = "^[a-zA-Z0-9_]+$"; From d4d94bf21e93f8cbe246c6dd219931371908bcc6 Mon Sep 17 00:00:00 2001 From: Rishi Mondal Date: Fri, 27 Dec 2024 01:40:31 +0530 Subject: [PATCH 4/5] Update packages/imperative/CHANGELOG.md Co-authored-by: Timothy Johnson Signed-off-by: Rishi Mondal --- packages/imperative/CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index 14224c398..16579208e 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -4,9 +4,7 @@ All notable changes to the Imperative package will be documented in this file. ## `8.10.2` -- bugfix: fixed a typo in the syntax validation code for positional arguments. the bug caused the validation to never fail. [#2384](https://github.com/zowe/zowe-cli/pull/2384) -- enhancement: added a regression test to validate the fix. [#2384](https://github.com/zowe/zowe-cli/pull/2384) - (note: non-user-facing items like regression tests are typically not included in the changelog). +- 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` From ae834ef1ea02ba755b3478bb782cb41ebc4b31fa Mon Sep 17 00:00:00 2001 From: Rishi Mondal Date: Fri, 27 Dec 2024 01:40:44 +0530 Subject: [PATCH 5/5] Update packages/imperative/CHANGELOG.md Co-authored-by: Timothy Johnson Signed-off-by: Rishi Mondal --- packages/imperative/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index 16579208e..44265cddd 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to the Imperative package will be documented in this file. -## `8.10.2` +## 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)