This commit is contained in:
Looly 2022-01-20 09:57:24 +08:00
parent 9a88945386
commit 5c6e275750
3 changed files with 23 additions and 6 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.20 (2022-01-19)
# 5.7.20 (2022-01-20)
### 🐣新特性
* 【core 】 增加对null值友好的groupingBy操作的Collector实现可指定map类型pr#498@Gitee
@ -27,6 +27,7 @@
* 【core 】 修复Opt.ofTry中并发环境下线程安全问题pr#504@Gitee
* 【core 】 修复PatternFinder中end边界判断问题issue#2099@Github
* 【core 】 修复格式化为中文日期时0被处理为空串pr#507@Gitee
* 【core 】 修复UrlPath转义冒号问题issue#I4RA42@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.7.19 (2022-01-07)

View File

@ -117,7 +117,10 @@ public class UrlPath {
}
/**
* 构建path前面带'/'
* 构建path前面带'/'<br>
* <pre>
* path = path-abempty / path-absolute / path-noscheme / path-rootless / path-empty
* </pre>
*
* @param charset encode编码null表示不做encode
* @return 如果没有任何内容则返回空字符串""
@ -129,10 +132,14 @@ public class UrlPath {
final StringBuilder builder = new StringBuilder();
for (String segment : segments) {
// 根据https://www.ietf.org/rfc/rfc3986.html#section-3.3定义
// path的第一部分允许有":"其余部分不允许
// 在此处的Path部分特指host之后的部分即不包含第一部分
builder.append(CharUtil.SLASH).append(RFC3986.SEGMENT_NZ_NC.encode(segment, charset));
if(builder.length() == 0){
// 根据https://www.ietf.org/rfc/rfc3986.html#section-3.3定义
// path的第一部分不允许有":"其余部分允许
// 在此处的Path部分特指host之后的部分即不包含第一部分
builder.append(CharUtil.SLASH).append(RFC3986.SEGMENT_NZ_NC.encode(segment, charset));
} else {
builder.append(CharUtil.SLASH).append(RFC3986.SEGMENT.encode(segment, charset));
}
}
if (StrUtil.isEmpty(builder)) {
// 空白追加是保证以/开头

View File

@ -251,6 +251,15 @@ public class UrlBuilderTest {
Assert.assertEquals(urlStr, urlBuilder.toString());
}
@Test
public void encodePathTest2(){
// https://gitee.com/dromara/hutool/issues/I4RA42
// Path中`:`在第一个segment需要转义之后的不需要
final String urlStr = "https://hutool.cn/aa/bb/Pre-K,Kindergarten,First,Second,Third,Fourth,Fifth/Page:3";
final UrlBuilder urlBuilder = UrlBuilder.ofHttp(urlStr, CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals(urlStr, urlBuilder.toString());
}
@Test
public void gimg2Test(){
String url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F1114%2F0H320120Z3%2F200H3120Z3-6-1200.jpg&refer=http%3A%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621996490&t=8c384c2823ea453da15a1b9cd5183eea";