Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct regex match condition in SyntaxValidator #2384

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion packages/imperative/src/cmd/src/syntax/SyntaxValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down