mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
fix double slash for append and getCompleteUrl of HttpUtil
This commit is contained in:
@@ -197,7 +197,11 @@ public final class HttpUtil
|
|||||||
*/
|
*/
|
||||||
public static String append(String uri, String suffix)
|
public static String append(String uri, String suffix)
|
||||||
{
|
{
|
||||||
if (!uri.endsWith(SEPARATOR_PATH) &&!suffix.startsWith(SEPARATOR_PATH))
|
if ( uri.endsWith(SEPARATOR_PATH) && suffix.startsWith(SEPARATOR_PATH) )
|
||||||
|
{
|
||||||
|
uri = uri.substring( 0, uri.length() - 1 );
|
||||||
|
}
|
||||||
|
else if (!uri.endsWith(SEPARATOR_PATH) &&!suffix.startsWith(SEPARATOR_PATH))
|
||||||
{
|
{
|
||||||
uri = uri.concat(SEPARATOR_PATH);
|
uri = uri.concat(SEPARATOR_PATH);
|
||||||
}
|
}
|
||||||
@@ -490,18 +494,7 @@ public final class HttpUtil
|
|||||||
public static String getCompleteUrl(ScmConfiguration configuration,
|
public static String getCompleteUrl(ScmConfiguration configuration,
|
||||||
String path)
|
String path)
|
||||||
{
|
{
|
||||||
String url = configuration.getBaseUrl();
|
return append(configuration.getBaseUrl(), path);
|
||||||
|
|
||||||
if (url.endsWith(SEPARATOR_PATH) && path.startsWith(SEPARATOR_PATH))
|
|
||||||
{
|
|
||||||
url = url.substring(0, url.length());
|
|
||||||
}
|
|
||||||
else if (!path.startsWith(SEPARATOR_PATH))
|
|
||||||
{
|
|
||||||
path = SEPARATOR_PATH.concat(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return url.concat(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -54,6 +54,33 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
public class HttpUtilTest
|
public class HttpUtilTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void appendTest()
|
||||||
|
{
|
||||||
|
//J-
|
||||||
|
assertEquals(
|
||||||
|
"http://www.scm-manager/scm/test",
|
||||||
|
HttpUtil.append("http://www.scm-manager/scm/", "test")
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
"http://www.scm-manager/scm/test",
|
||||||
|
HttpUtil.append("http://www.scm-manager/scm", "test")
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
"http://www.scm-manager/scm/test",
|
||||||
|
HttpUtil.append("http://www.scm-manager/scm", "/test")
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
"http://www.scm-manager/scm/test",
|
||||||
|
HttpUtil.append("http://www.scm-manager/scm/", "/test")
|
||||||
|
);
|
||||||
|
//J+
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -173,6 +200,10 @@ public class HttpUtilTest
|
|||||||
HttpUtil.getCompleteUrl(config, "test/path"));
|
HttpUtil.getCompleteUrl(config, "test/path"));
|
||||||
assertEquals("http://www.scm-manager.org/scm/test/path",
|
assertEquals("http://www.scm-manager.org/scm/test/path",
|
||||||
HttpUtil.getCompleteUrl(config, "/test/path"));
|
HttpUtil.getCompleteUrl(config, "/test/path"));
|
||||||
|
|
||||||
|
config.setBaseUrl("http://www.scm-manager.org/scm/");
|
||||||
|
assertEquals("http://www.scm-manager.org/scm/test/path",
|
||||||
|
HttpUtil.getCompleteUrl(config, "/test/path"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user