fix where username and password cannot both contain @

This commit is contained in:
Adrian Cole 2010-02-22 20:49:32 -08:00
parent 300963078c
commit b59faeb385
2 changed files with 8 additions and 2 deletions

View File

@ -202,8 +202,8 @@ public class HttpUtils {
if (uriPath.indexOf('@') != 1) {
List<String> parts = Lists.newArrayList(Splitter.on('@').split(uriPath));
String path = parts.remove(parts.size() - 1);
if (parts.size() == 2) {
parts = Lists.newArrayList(urlEncode(parts.get(0) + "@" + parts.get(1), '/', ':'));
if (parts.size() > 1) {
parts = Lists.newArrayList(urlEncode(Joiner.on('@').join(parts), '/', ':'));
}
parts.add(urlEncode(path, '/', ':'));
uriPath = Joiner.on('@').join(parts);

View File

@ -71,6 +71,12 @@ public class HttpUtilsTest extends PerformanceTest {
assertEquals(creds, URI.create("compute://user%40domain:password@terremark"));
}
public void testTerremark2() {
URI creds = HttpUtils.createUri("compute://user@domain:passw@rd@terremark");
assertEquals(creds.getUserInfo(), "user@domain:passw@rd");
assertEquals(creds, URI.create("compute://user%40domain:passw%40rd@terremark"));
}
public void testCloudFiles() {
URI creds = HttpUtils.createUri("compute://account:h3c@cloudfiles/container-hyphen/prefix");
assertEquals(creds, URI.create("compute://account:h3c@cloudfiles/container-hyphen/prefix"));