mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug
This commit is contained in:
parent
ce504c2a3e
commit
ff3dc01f04
@ -3,11 +3,12 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.19 (2021-12-25)
|
||||
# 5.7.19 (2021-12-29)
|
||||
|
||||
### 🐣新特性
|
||||
### 🐞Bug修复
|
||||
* 【http 】 HttpUtil重定向次数失效问题(issue#I4O28Q@Gitee)
|
||||
* 【core 】 修复UrlPath空白path多/问题(issue#I49KAL@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.7.18 (2021-12-25)
|
||||
|
@ -105,9 +105,11 @@ public class UrlPath {
|
||||
}
|
||||
|
||||
path = fixPath(path);
|
||||
final List<String> split = StrUtil.split(path, '/');
|
||||
for (String seg : split) {
|
||||
addInternal(URLDecoder.decodeForPath(seg, charset), false);
|
||||
if(StrUtil.isNotEmpty(path)){
|
||||
final List<String> split = StrUtil.split(path, '/');
|
||||
for (String seg : split) {
|
||||
addInternal(URLDecoder.decodeForPath(seg, charset), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,9 +134,14 @@ public class UrlPath {
|
||||
// 在此处的Path部分特指host之后的部分,即不包含第一部分
|
||||
builder.append(CharUtil.SLASH).append(RFC3986.SEGMENT_NZ_NC.encode(segment, charset));
|
||||
}
|
||||
if (withEngTag || StrUtil.isEmpty(builder)) {
|
||||
if (StrUtil.isEmpty(builder)) {
|
||||
// 空白追加是保证以/开头
|
||||
builder.append(CharUtil.SLASH);
|
||||
}else if (withEngTag && false == StrUtil.endWith(builder, CharUtil.SLASH)) {
|
||||
// 尾部没有/则追加,否则不追加
|
||||
builder.append(CharUtil.SLASH);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
@ -320,4 +320,22 @@ public class UrlBuilderTest {
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(url);
|
||||
Assert.assertEquals(url, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fragmentTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I49KAL#note_8060874
|
||||
String url = "https://www.hutool.cn/#/a/b?timestamp=1640391380204";
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(url);
|
||||
|
||||
Assert.assertEquals(url, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fragmentAppendParamTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I49KAL#note_8060874
|
||||
String url = "https://www.hutool.cn/#/a/b";
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(url);
|
||||
builder.setFragment(builder.getFragment() + "?timestamp=1640391380204");
|
||||
Assert.assertEquals("https://www.hutool.cn/#/a/b?timestamp=1640391380204", builder.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user