mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bug
This commit is contained in:
parent
228d0a438a
commit
8c0fb77421
@ -107,10 +107,12 @@ public final class UrlBuilder implements Builder<String> {
|
||||
public static UrlBuilder ofHttp(String httpUrl, final Charset charset) {
|
||||
Assert.notBlank(httpUrl, "Http url must be not blank!");
|
||||
|
||||
final int sepIndex = httpUrl.indexOf("://");
|
||||
if (sepIndex < 0) {
|
||||
httpUrl = "http://" + httpUrl.trim();
|
||||
httpUrl = StrUtil.trimStart(httpUrl);
|
||||
// issue#I66CIR
|
||||
if(false == StrUtil.startWithAnyIgnoreCase(httpUrl, "http://", "https://")){
|
||||
httpUrl = "http://" + httpUrl;
|
||||
}
|
||||
|
||||
return of(httpUrl, charset);
|
||||
}
|
||||
|
||||
|
@ -479,4 +479,19 @@ public class UrlBuilderTest {
|
||||
UrlBuilder.of().addPath("//");
|
||||
UrlBuilder.of().addPath("//a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofHttpTest() {
|
||||
UrlBuilder ofHttp = UrlBuilder.ofHttp("http://hutool.cn");
|
||||
Assert.assertEquals("http://hutool.cn", ofHttp.toString());
|
||||
|
||||
ofHttp = UrlBuilder.ofHttp("https://hutool.cn");
|
||||
Assert.assertEquals("https://hutool.cn", ofHttp.toString());
|
||||
|
||||
ofHttp = UrlBuilder.ofHttp("hutool.cn");
|
||||
Assert.assertEquals("http://hutool.cn", ofHttp.toString());
|
||||
|
||||
ofHttp = UrlBuilder.ofHttp("hutool.cn?old=http://aaa");
|
||||
Assert.assertEquals("http://hutool.cn?old=http://aaa", ofHttp.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user