Skip to content

Commit

Permalink
Merge pull request #241 from rundeck/issue/180
Browse files Browse the repository at this point in the history
Fix #180 prevent invalid project name
  • Loading branch information
gschueler authored Jun 25, 2019
2 parents 2e321ae + 7112d8a commit edf0312
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

import java.io.IOException;
import java.util.function.Function;
import java.util.regex.Pattern;

import static org.rundeck.client.tool.options.ProjectRequiredNameOptions.PROJECT_NAME_PATTERN;

/**
* Base type for commands in Rd
Expand Down Expand Up @@ -168,7 +171,18 @@ public String projectOrEnv(final ProjectNameOptions options) throws InputError {
return options.getProject();
}
try {
return getAppConfig().require("RD_PROJECT", "or specify as `-p/--project value` : Project name.");
String
rd_project =
getAppConfig().require("RD_PROJECT", "or specify as `-p/--project value` : Project name.");
Pattern pat = Pattern.compile(PROJECT_NAME_PATTERN);
if (!pat.matcher(rd_project).matches()) {
throw new InputError(String.format(
"Cannot match (%s) to pattern: /%s/ : RD_PROJECT",
rd_project,
PROJECT_NAME_PATTERN
));
}
return rd_project;
} catch (ConfigSource.ConfigSourceError configSourceError) {
throw new InputError(configSourceError.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @since 4/10/17
*/
public interface ProjectRequiredNameOptions {
@Option(shortName = "p", longName = "project", description = "Project name")
static final String PROJECT_NAME_PATTERN = "^[-_a-zA-Z0-9+][-\\._a-zA-Z0-9+]*$";

@Option(shortName = "p", longName = "project", description = "Project name", pattern = PROJECT_NAME_PATTERN)
String getProject();
}

0 comments on commit edf0312

Please sign in to comment.