Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

#308 Extend repository validation by allowing port number. #309

Merged
merged 4 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class BuildMojo extends AbstractDockerMojo {
/**
* Regex for a valid docker repository name. Used in validateRepository().
*/
private static final String VALID_REPO_REGEX = "^([a-z0-9_.-])+(\\/[a-z0-9_.-]+)*$";
private static final String VALID_REPO_REGEX = "^([a-z0-9_.-])+(:[0-9]{1,5})?(\\/[a-z0-9_.-]+)*$";

/**
* Directory containing the the build context. This is typically the directory that contains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void testSuccess() throws MojoFailureException {
assertTrue("Start and end with dots", BuildMojo.validateRepository(".start.and.end."));
assertTrue("Start and end with hyphens", BuildMojo.validateRepository("-start-and-end-"));
assertTrue("Start and end with underscores", BuildMojo.validateRepository("_start_and_end_"));
assertTrue("May contain port", BuildMojo.validateRepository("example.com:443/okay./.path"));
// Forward slash delimits the repo user from the repo name; strictly speaking,
// you're allowed only one slash, somewhere in the middle.
assertTrue("Multipart", BuildMojo.validateRepository("with/forwardslash"));
Expand All @@ -59,5 +60,8 @@ public void testFailCases() {
assertFalse("Symbols didn't fail", BuildMojo.validateRepository("ddddddDd+dddd"));
assertFalse("Starting slash didn't fail", BuildMojo.validateRepository("/atstart"));
assertFalse("Ending slash didn't fail", BuildMojo.validateRepository("atend/"));
assertFalse("Only port", BuildMojo.validateRepository(":443"));
assertFalse(
"Port exceeding range", BuildMojo.validateRepository("example.com:100000/myproject"));
}
}