# HG changeset patch # User Pavel.Sher # Date 1263929404 -10800 # Node ID 889f1bd868f8e73cc43c3226a40bdde522d15321 # Parent 99fc78c3e8db227fc4745473ee178a8db979a887# Parent a0aea01c32b0f53ee2a9e714e7fccac851e9442a improve repository url parsing (integrated) diff -r 99fc78c3e8db -r 889f1bd868f8 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Wed Dec 09 10:38:52 2009 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Tue Jan 19 22:30:04 2010 +0300 @@ -104,18 +104,25 @@ public String getRepositoryUrl() { if (containsCredentials(myRepository)) return myRepository; - String cre = ""; - if (!StringUtil.isEmpty(myUsername)) { - cre += myUsername; - if (!StringUtil.isEmpty(myPassword)) { - cre += ":" + myPassword; - } - cre += "@"; - } - for (String proto: AUTH_PROTOS) { if (myRepository.startsWith(proto)) { - return proto + cre + myRepository.substring(proto.length()); + String repoUrl = myRepository.substring(proto.length()); + int endIdx = repoUrl.indexOf('@'); + int slashIdx = repoUrl.indexOf('/'); + if (endIdx != -1 && slashIdx > endIdx) { + repoUrl = repoUrl.substring(endIdx+1); + } + + String cre = ""; + if (!StringUtil.isEmpty(myUsername)) { + cre += myUsername; + if (!StringUtil.isEmpty(myPassword)) { + cre += ":" + myPassword; + } + cre += "@"; + } + + return proto + cre + repoUrl; } } diff -r 99fc78c3e8db -r 889f1bd868f8 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java Tue Jan 19 22:30:04 2010 +0300 @@ -0,0 +1,47 @@ +package jetbrains.buildServer.buildTriggers.vcs.mercurial; + +import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.Settings; +import jetbrains.buildServer.vcs.impl.VcsRootImpl; +import junit.framework.Assert; +import org.testng.annotations.Test; + +import java.io.File; + +/** + * @author Pavel.Sher + */ +@Test +public class SettingsTest extends Assert { + public void test_url_without_credentials() { + VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path"); + Settings settings = new Settings(new File("."), vcsRoot); + assertEquals("http://user:pwd@host.com/path", settings.getRepositoryUrl()); + } + + public void test_url_with_credentials() { + VcsRootImpl vcsRoot = createVcsRoot("http://user:pwd@host.com/path"); + Settings settings = new Settings(new File("."), vcsRoot); + assertEquals("http://user:pwd@host.com/path", settings.getRepositoryUrl()); + } + + public void test_url_with_username() { + VcsRootImpl vcsRoot = createVcsRoot("http://user@host.com/path"); + Settings settings = new Settings(new File("."), vcsRoot); + assertEquals("http://user:pwd@host.com/path", settings.getRepositoryUrl()); + } + + public void test_url_with_at_after_slash() { + VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path@"); + Settings settings = new Settings(new File("."), vcsRoot); + assertEquals("http://user:pwd@host.com/path@", settings.getRepositoryUrl()); + } + + private VcsRootImpl createVcsRoot(String url) { + VcsRootImpl vcsRoot = new VcsRootImpl(1, Constants.VCS_NAME); + vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, "hg.exe"); + vcsRoot.addProperty(Constants.REPOSITORY_PROP, url); + vcsRoot.addProperty(Constants.USERNAME, "user"); + vcsRoot.addProperty(Constants.PASSWORD, "pwd"); + return vcsRoot; + } +}