This commit is contained in:
Looly 2022-08-27 01:06:01 +08:00
parent d815af53de
commit 282d6245a4
2 changed files with 13 additions and 2 deletions

View File

@ -1,11 +1,13 @@
package cn.hutool.core.net.url;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.net.RFC3986;
import cn.hutool.core.net.URLDecoder;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.ObjUtil;
import java.nio.charset.Charset;
import java.util.LinkedList;
@ -55,12 +57,12 @@ public class UrlPath {
}
/**
* 获取path的节点列表
* 获取path的节点列表如果列表为空返回{@link ListUtil#empty()}
*
* @return 节点列表
*/
public List<String> getSegments() {
return this.segments;
return ObjUtil.defaultIfNull(this.segments, ListUtil.empty());
}
/**

View File

@ -470,4 +470,13 @@ public class UrlBuilderTest {
Assert.assertEquals("127.0.0.1:8080", builder.getAuthority());
}
@Test
public void addPathTest(){
//https://gitee.com/dromara/hutool/issues/I5O4ML
UrlBuilder.of().addPath("");
UrlBuilder.of().addPath("/");
UrlBuilder.of().addPath("//");
UrlBuilder.of().addPath("//a");
}
}