# HG changeset patch # User Dmitry Neverov # Date 1285664944 -14400 # Node ID 8eab713b01a4502406c34cc845d3966224d61fa3 # Parent a13422ae169d0b4fdea8421d0aeebd285d05604f Create repositoryUrl using java.util.URI (it escapes illegal characters) diff -r a13422ae169d -r 8eab713b01a4 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Tue Sep 28 12:49:37 2010 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Tue Sep 28 13:09:04 2010 +0400 @@ -94,9 +94,9 @@ private final static Set AUTH_PROTOS = new HashSet(); static { - AUTH_PROTOS.add("http://"); - AUTH_PROTOS.add("https://"); - AUTH_PROTOS.add("ssh://"); + AUTH_PROTOS.add("http"); + AUTH_PROTOS.add("https"); + AUTH_PROTOS.add("ssh"); } /** @@ -106,28 +106,14 @@ public String getRepositoryUrl() { if (containsCredentials(myRepository)) return myRepository; - for (String proto: AUTH_PROTOS) { - if (myRepository.startsWith(proto)) { - 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; + try { + URI repoURI = createUriWithCredentials(myRepository); + if (AUTH_PROTOS.contains(repoURI.getScheme())) { + return repoURI.toASCIIString(); } + } catch (URISyntaxException e) { + //ignore } - return myRepository; } @@ -135,7 +121,7 @@ try { URI repositoryURI = new URI(repository); String scheme = repositoryURI.getScheme(); - if (AUTH_PROTOS.contains(scheme + "://")) { + if (AUTH_PROTOS.contains(scheme)) { String userInfo = repositoryURI.getUserInfo(); return userInfo != null && userInfo.contains(":"); } else { @@ -146,6 +132,28 @@ } } + private URI createUriWithCredentials(final String uri) throws URISyntaxException { + URI repositoryURI = new URI(uri); + return new URI(repositoryURI.getScheme(), + createUserInfo(), + repositoryURI.getHost(), + repositoryURI.getPort(), + repositoryURI.getPath(), + repositoryURI.getQuery(), + repositoryURI.getFragment()); + } + + private String createUserInfo() { + String userInfo = ""; + if (!StringUtil.isEmpty(myUsername)) { + userInfo += myUsername; + if (!StringUtil.isEmpty(myPassword)) { + userInfo += ":" + myPassword; + } + } + return userInfo; + } + public void setHgCommandPath(@NotNull final String hgCommandPath) { myHgCommandPath = hgCommandPath; }