Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-progress-bar-to-dir-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj authored Jan 7, 2025
2 parents 83f1e44 + 7ac5ab7 commit 9145334
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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.3`

- BugFix: Resolved an issue where extraneous base profiles were created in project configurations when a nested profile property was updated. [#2400](https://github.com/zowe/zowe-cli/pull/2400)
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 @@ -46,6 +46,9 @@ describe("Imperative should provide advanced syntax validation rules", () => {
function tryOptions(optionString: string, shouldSucceed: boolean, expectedText?: string[]) {

const options = yargsParser.detailed(optionString, configuration).argv;
ValidationTestCommand.positionals?.forEach((p) => {
options[p.name] = options._.shift(); // fake out named positionals
});
options._ = ["test", "validation-test"].concat(options._ || []); // fake out command structure
options[Constants.JSON_OPTION] = true;
delete options["--"]; // delete extra yargs parse field
Expand Down Expand Up @@ -525,6 +528,28 @@ 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 = "^\\w+$";
ValidationTestCommand.positionals = [{
name: invalidPositional,
type: "string",
description: "Invalid positional",
regex: regexForPositional,
}];

return tryOptions.bind(this)(
minValidOptions + "inv@lid",
false,
[
"Invalid format specified for positional option:",
invalidPositional,
"Option must match the following regular expression:",
regexForPositional
]
);
});

describe("We should be able to validate positional arguments of type 'number'", () => {
const numberCommand: ICommandDefinition = {
name: "gimme-number", aliases: [],
Expand Down

0 comments on commit 9145334

Please sign in to comment.