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 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
MAVRICK-1 marked this conversation as resolved.
Show resolved Hide resolved

## `8.8.3`

- BugFix: Modified 8.8.2 bugfix to correct web help alias. [#2361](https://github.com/zowe/zowe-cli/pull/2361)
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.only("If a positional argument does not match the defined regex, the command should fail", async () => {
MAVRICK-1 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading