Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
Allow usernames containing "@" and addind escaping "@" when building …
Browse files Browse the repository at this point in the history
…URL (#42)
  • Loading branch information
tobias-richter authored Jan 7, 2020
1 parent d065218 commit 39f79ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/io/wcm/devops/jenkins/pipeline/scm/GitRepository.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class GitRepository {
GitRepository(Script script, String url) {
this.script = script
this.url = url
Matcher matcher = url =~ /(https?:\\/\\/|(?:ssh:\\/\\/)?)(?:([^@\/]+)@)?((?:[\w.\-_]+)(?::\d+)?)(?:\\/|:)((?:[\w-_\\/]*))\\/(.*)/
Matcher matcher = url =~ /(https?:\\/\\/|(?:ssh:\\/\\/)?)(?:([^\/]+)@)?((?:[\w.\-_]+)(?::\d+)?)(?:\\/|:)((?:[\w-_\\/]*))\\/(.*)/
if (matcher) {
List matches = matcher[0]

Expand Down Expand Up @@ -159,7 +159,7 @@ class GitRepository {
if (isHttp() || isHttps()) {
// add a username if present
if (username != null) {
ret += "${username}@"
ret += "${username.replace("@","%40")}@"
}
// add the server, group and project
ret += "${server}/${group}/${project}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class GitRepositoryTest extends CpsScriptTestBase {
}

@Test
void shouldManiupulateHttpsUsername() {
void shouldManipulateHttpsUsername() {
String url = "https://[email protected]:443/wcm-io-devops/jenkins-pipeline-library.git"
underTest = new GitRepository(this.script, url)
assertEquals(url, underTest.getUrl())
Expand All @@ -176,6 +176,14 @@ class GitRepositoryTest extends CpsScriptTestBase {
assertEquals(url, underTest.getUrl())
}

@Test
void shouldEscapeAtInUsername() {
String url = "https://username1@[email protected]:443/wcm-io-devops/jenkins-pipeline-library.git"
String expectedUrl = "https://username1%[email protected]:443/wcm-io-devops/jenkins-pipeline-library.git"
underTest = new GitRepository(this.script, url)
assertEquals(expectedUrl, underTest.getUrl())
}

@Test(expected = AbortException.class)
void shouldThrowExceptionOnInvalidUrl() {
underTest = new GitRepository(this.script, "")
Expand Down

0 comments on commit 39f79ea

Please sign in to comment.