If URI has no context path add one ("/")

Fixes gh-131
This commit is contained in:
Dave Syer
2015-04-29 11:38:00 +02:00
parent 5d1af78f91
commit 98b64aa4cb
2 changed files with 18 additions and 2 deletions

View File

@@ -85,6 +85,11 @@ public abstract class AbstractScmEnvironmentRepository implements EnvironmentRep
while (uri.endsWith("/")) {
uri = uri.substring(0, uri.length() - 1);
}
int index = uri.indexOf("://");
if (index>0 && !uri.substring(index+"://".length()).contains("/")) {
// If there's no context path add one
uri = uri + "/";
}
this.uri = uri;
}

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.config.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
@@ -123,5 +122,17 @@ public class JGitEnvironmentRepositoryTests {
assertEquals(repository.getUri() + "/bar.properties", environment
.getPropertySources().get(0).getName());
}
@Test
public void uriWithHostOnly() throws Exception {
repository.setUri("git://localhost");
assertEquals("git://localhost/", repository.getUri());
}
@Test
public void uriWithHostAndPath() throws Exception {
repository.setUri("git://localhost/foo/");
assertEquals("git://localhost/foo", repository.getUri());
}
}