mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
URLUtil.normalize(java.lang.String, boolean, boolean) 新增重载方法
This commit is contained in:
parent
78404a51ad
commit
431c1183c4
@ -14,14 +14,7 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.net.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarFile;
|
||||
@ -693,6 +686,23 @@ public class URLUtil {
|
||||
* @since 4.4.1
|
||||
*/
|
||||
public static String normalize(String url, boolean isEncodePath) {
|
||||
return normalize(url, isEncodePath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准化URL字符串,包括:
|
||||
*
|
||||
* <pre>
|
||||
* 1. 多个/替换为一个
|
||||
* </pre>
|
||||
*
|
||||
* @param url URL字符串
|
||||
* @param isEncodePath 是否对URL中path部分的中文和特殊字符做转义(不包括 http:, /和域名部分)
|
||||
* @param replaceSlash 是否替换url body中的 //
|
||||
* @return 标准化后的URL字符串
|
||||
* @since 4.4.1
|
||||
*/
|
||||
public static String normalize(String url, boolean isEncodePath, boolean replaceSlash) {
|
||||
if (StrUtil.isBlank(url)) {
|
||||
return url;
|
||||
}
|
||||
@ -720,8 +730,10 @@ public class URLUtil {
|
||||
body = body.replaceAll("^[\\\\/]+", StrUtil.EMPTY);
|
||||
// 替换多个\或/为单个/
|
||||
body = body.replace("\\", "/");
|
||||
//issue#I25MZL,双斜杠在URL中是允许存在的,不做替换
|
||||
//.replaceAll("//+", "/");
|
||||
//issue#I25MZL,双斜杠在URL中是允许存在的,默认不做替换
|
||||
if (replaceSlash) {
|
||||
body = body.replaceAll("//+", "/");
|
||||
}
|
||||
}
|
||||
|
||||
final int pathSepIndex = StrUtil.indexOf(body, '/');
|
||||
|
Loading…
x
Reference in New Issue
Block a user