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
f88e7ab2f3
commit
87b88b395e
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.7.16 (2021-10-24)
|
# 5.7.16 (2021-10-26)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 增加DateTime.toLocalDateTime
|
* 【core 】 增加DateTime.toLocalDateTime
|
||||||
@ -13,6 +13,7 @@
|
|||||||
* 【core 】 NumberUtil.compare修正注释说明(issue#I4FAJ1@Gitee)
|
* 【core 】 NumberUtil.compare修正注释说明(issue#I4FAJ1@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -322,13 +322,25 @@ public final class UrlBuilder implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加路径节点
|
* 增加路径,在现有路径基础上追加路径
|
||||||
|
*
|
||||||
|
* @param path 路径,例如aaa/bbb/ccc
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public UrlBuilder addPath(CharSequence path) {
|
||||||
|
UrlPath.of(path, this.charset).getSegments().forEach(this::addPathSegment);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加路径节点,路径节点中的"/"会被转义为"%2F"
|
||||||
*
|
*
|
||||||
* @param segment 路径节点
|
* @param segment 路径节点
|
||||||
* @return this
|
* @return this
|
||||||
|
* @since 5.7.16
|
||||||
*/
|
*/
|
||||||
public UrlBuilder addPath(String segment) {
|
public UrlBuilder addPathSegment(CharSequence segment) {
|
||||||
if (StrUtil.isBlank(segment)) {
|
if (StrUtil.isEmpty(segment)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (null == this.path) {
|
if (null == this.path) {
|
||||||
@ -341,19 +353,13 @@ public final class UrlBuilder implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 追加path节点
|
* 追加path节点
|
||||||
*
|
*
|
||||||
* @param segment path节点
|
* @param path path节点
|
||||||
* @return this
|
* @return this
|
||||||
|
* @deprecated 方法重复,请使用{@link #addPath(CharSequence)}
|
||||||
*/
|
*/
|
||||||
public UrlBuilder appendPath(CharSequence segment) {
|
@Deprecated
|
||||||
if (StrUtil.isEmpty(segment)) {
|
public UrlBuilder appendPath(CharSequence path) {
|
||||||
return this;
|
return addPath(path);
|
||||||
}
|
|
||||||
|
|
||||||
if (this.path == null) {
|
|
||||||
this.path = new UrlPath();
|
|
||||||
}
|
|
||||||
this.path.add(segment);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,7 @@ public class UrlPath {
|
|||||||
* @param charset decode用的编码,null表示不做decode
|
* @param charset decode用的编码,null表示不做decode
|
||||||
* @return UrlPath
|
* @return UrlPath
|
||||||
*/
|
*/
|
||||||
public static UrlPath of(String pathStr, Charset charset) {
|
public static UrlPath of(CharSequence pathStr, Charset charset) {
|
||||||
final UrlPath urlPath = new UrlPath();
|
final UrlPath urlPath = new UrlPath();
|
||||||
urlPath.parse(pathStr, charset);
|
urlPath.parse(pathStr, charset);
|
||||||
return urlPath;
|
return urlPath;
|
||||||
@ -97,7 +97,7 @@ public class UrlPath {
|
|||||||
* @param charset decode编码,null表示不解码
|
* @param charset decode编码,null表示不解码
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public UrlPath parse(String path, Charset charset) {
|
public UrlPath parse(CharSequence path, Charset charset) {
|
||||||
if (StrUtil.isNotEmpty(path)) {
|
if (StrUtil.isNotEmpty(path)) {
|
||||||
// 原URL中以/结尾,则这个规则需保留,issue#I1G44J@Gitee
|
// 原URL中以/结尾,则这个规则需保留,issue#I1G44J@Gitee
|
||||||
if(StrUtil.endWith(path, CharUtil.SLASH)){
|
if(StrUtil.endWith(path, CharUtil.SLASH)){
|
||||||
|
@ -281,4 +281,29 @@ public class UrlBuilderTest {
|
|||||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp(url);
|
final UrlBuilder urlBuilder = UrlBuilder.ofHttp(url);
|
||||||
Assert.assertEquals(url, urlBuilder.toString());
|
Assert.assertEquals(url, urlBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addPathEncodeTest(){
|
||||||
|
String url = UrlBuilder.create()
|
||||||
|
.setScheme("https")
|
||||||
|
.setHost("domain.cn")
|
||||||
|
.addPath("api")
|
||||||
|
.addPath("xxx")
|
||||||
|
.addPath("bbb")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Assert.assertEquals("https://domain.cn/api/xxx/bbb", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addPathEncodeTest2(){
|
||||||
|
// https://github.com/dromara/hutool/issues/1912
|
||||||
|
String url = UrlBuilder.create()
|
||||||
|
.setScheme("https")
|
||||||
|
.setHost("domain.cn")
|
||||||
|
.addPath("/api/xxx/bbb")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Assert.assertEquals("https://domain.cn/api/xxx/bbb", url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user