mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
Merge pull request #654 from sukaiyi/v5-dev
issue[651]: URLUtil.normalize support ipv6
This commit is contained in:
commit
affcc57598
@ -637,7 +637,7 @@ public class URLUtil {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param url URL字符串
|
* @param url URL字符串
|
||||||
* @param isEncodeBody 是否对URL中body部分的中文和特殊字符做转义(不包括http:和/)
|
* @param isEncodeBody 是否对URL中body部分的中文和特殊字符做转义(不包括 http:, /和域名部分)
|
||||||
* @return 标准化后的URL字符串
|
* @return 标准化后的URL字符串
|
||||||
* @since 4.4.1
|
* @since 4.4.1
|
||||||
*/
|
*/
|
||||||
@ -667,9 +667,17 @@ public class URLUtil {
|
|||||||
body = body.replaceAll("^[\\\\/]+", StrUtil.EMPTY);
|
body = body.replaceAll("^[\\\\/]+", StrUtil.EMPTY);
|
||||||
// 替换多个\或/为单个/
|
// 替换多个\或/为单个/
|
||||||
body = body.replace("\\", "/").replaceAll("//+", "/");
|
body = body.replace("\\", "/").replaceAll("//+", "/");
|
||||||
if (isEncodeBody) {
|
|
||||||
body = encode(body);
|
final int pathSepIndex = StrUtil.indexOf(body, '/');
|
||||||
|
String domain = body;
|
||||||
|
String path = "";
|
||||||
|
if (pathSepIndex > 0) {
|
||||||
|
domain = StrUtil.subPre(body, pathSepIndex);
|
||||||
|
path = StrUtil.subSuf(body, pathSepIndex);
|
||||||
}
|
}
|
||||||
return pre + body + StrUtil.nullToEmpty(params);
|
if (isEncodeBody) {
|
||||||
|
path = encode(path);
|
||||||
|
}
|
||||||
|
return pre + domain + path + StrUtil.nullToEmpty(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -71,7 +71,7 @@ public class HttpUtilTest {
|
|||||||
FileUtil.writeBytes(str, "f:/test/2D.jpg");
|
FileUtil.writeBytes(str, "f:/test/2D.jpg");
|
||||||
Console.log(str);
|
Console.log(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void get12306Test() {
|
public void get12306Test() {
|
||||||
@ -274,4 +274,10 @@ public class HttpUtilTest {
|
|||||||
String mimeType = HttpUtil.getMimeType("aaa.aaa");
|
String mimeType = HttpUtil.getMimeType("aaa.aaa");
|
||||||
Assert.assertNull(mimeType);
|
Assert.assertNull(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ipv6Test() {
|
||||||
|
String result = HttpUtil.get("http://[fe80::8f8:2022:a603:d180]:9439");
|
||||||
|
Console.log(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user