From 062c027911be890fca4b7df8508d118c05a97bcc Mon Sep 17 00:00:00 2001 From: M Golshan Date: Fri, 10 May 2024 16:25:30 -0400 Subject: [PATCH 1/2] Add unit tests for supported dots in usernames --- .../plugins/github_branch_source/GitHubSCMSourceTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java index 1a58db43e..17ed54257 100644 --- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java @@ -945,6 +945,8 @@ public void testUserNamesWithAndWithoutUnderscores() { assertTrue("a".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); assertTrue("0".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); assertTrue("a-b-c-d-e-f-g".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); + assertTrue("a.b".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); + assertTrue("a.b.c".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); // Valid names should contain alphanumeric characters or single hyphens, and cannot begin or end // with a hyphen, and have a 39 char limit @@ -960,5 +962,8 @@ public void testUserNamesWithAndWithoutUnderscores() { assertFalse("user123-_org456".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); assertFalse("user123_org456-code789".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); assertFalse("user123_org456_code789".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); + assertFalse(".user123_org456_code789".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); + assertFalse("user123_org456_code789.".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); + assertFalse("a..b".matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)); } } From 202f75e6b5ca018d3c44afe1e3aec45886dc6be3 Mon Sep 17 00:00:00 2001 From: M Golshan Date: Fri, 10 May 2024 16:26:57 -0400 Subject: [PATCH 2/2] Update the regex pattern to support dots in usernames --- .../jenkinsci/plugins/github_branch_source/GitHubSCMSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java index 7e1d00f1f..530dae533 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java @@ -151,7 +151,7 @@ public class GitHubSCMSource extends AbstractGitSCMSource { public static final String VALID_GITHUB_REPO_NAME = "^[0-9A-Za-z._-]+$"; public static final String VALID_GITHUB_USER_NAME = - "^(?=[A-Za-z0-9-_]{1,39}$)([A-Za-z0-9]((?:[A-Za-z0-9]+|-(?=[A-Za-z0-9]+))*)(_(?:[A-Za-z0-9]+))?)"; + "^(?=[A-Za-z0-9-_.]{1,39}$)([A-Za-z0-9]((?:[A-Za-z0-9]+|[-.](?=[A-Za-z0-9]+))*)(_(?:[A-Za-z0-9]+))?)"; public static final String VALID_GIT_SHA1 = "^[a-fA-F0-9]{40}$"; public static final String GITHUB_URL = GitHubServerConfig.GITHUB_URL; public static final String GITHUB_COM = "github.com";