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

Commit 15780af

Browse files
authored
Merge pull request #309 from mmaeller/#308
#308 Extend repository validation by allowing port number.
2 parents 9d441d4 + 2f8e561 commit 15780af

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

plugin/src/main/java/com/spotify/plugin/dockerfile/BuildMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class BuildMojo extends AbstractDockerMojo {
5353
/**
5454
* Regex for a valid docker repository name. Used in validateRepository().
5555
*/
56-
private static final String VALID_REPO_REGEX = "^([a-z0-9_.-])+(\\/[a-z0-9_.-]+)*$";
56+
private static final String VALID_REPO_REGEX = "^([a-z0-9_.-])+(:[0-9]{1,5})?(\\/[a-z0-9_.-]+)*$";
5757

5858
/**
5959
* Directory containing the the build context. This is typically the directory that contains

plugin/src/test/java/com/spotify/plugin/dockerfile/TestRepoNameValidation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void testSuccess() throws MojoFailureException {
4747
assertTrue("Start and end with dots", BuildMojo.validateRepository(".start.and.end."));
4848
assertTrue("Start and end with hyphens", BuildMojo.validateRepository("-start-and-end-"));
4949
assertTrue("Start and end with underscores", BuildMojo.validateRepository("_start_and_end_"));
50+
assertTrue("May contain port", BuildMojo.validateRepository("example.com:443/okay./.path"));
5051
// Forward slash delimits the repo user from the repo name; strictly speaking,
5152
// you're allowed only one slash, somewhere in the middle.
5253
assertTrue("Multipart", BuildMojo.validateRepository("with/forwardslash"));
@@ -59,5 +60,8 @@ public void testFailCases() {
5960
assertFalse("Symbols didn't fail", BuildMojo.validateRepository("ddddddDd+dddd"));
6061
assertFalse("Starting slash didn't fail", BuildMojo.validateRepository("/atstart"));
6162
assertFalse("Ending slash didn't fail", BuildMojo.validateRepository("atend/"));
63+
assertFalse("Only port", BuildMojo.validateRepository(":443"));
64+
assertFalse(
65+
"Port exceeding range", BuildMojo.validateRepository("example.com:100000/myproject"));
6266
}
6367
}

0 commit comments

Comments
 (0)