Skip to content

Commit

Permalink
Fix #180 prevent invalid project name
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jun 21, 2019
1 parent 1ac2dec commit 7112d8a
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 7112d8a

Please sign in to comment.