This commit is contained in:
Looly
2020-09-23 12:42:55 +08:00
parent 36f7909702
commit 67aa719b3c
6 changed files with 36 additions and 11 deletions

View File

@@ -483,13 +483,7 @@ public class URLUtil {
* @throws UtilException 包装URISyntaxException
*/
public static String getPath(String uriStr) {
URI uri;
try {
uri = new URI(uriStr);
} catch (URISyntaxException e) {
throw new UtilException(e);
}
return uri.getPath();
return toURI(uriStr).getPath();
}
/**
@@ -509,7 +503,7 @@ public class URLUtil {
String path = null;
try {
// URL对象的getPath方法对于包含中文或空格的问题
path = URLUtil.toURI(url).getPath();
path = toURI(url).getPath();
} catch (UtilException e) {
// ignore
}
@@ -569,7 +563,7 @@ public class URLUtil {
location = encode(location);
}
try {
return new URI(location);
return new URI(StrUtil.trim(location));
} catch (URISyntaxException e) {
throw new UtilException(e);
}

View File

@@ -1116,6 +1116,8 @@ public class ZipUtil {
* @since 5.0.5
*/
private static File buildFile(File outFile, String fileName) {
// 替换Windows路径分隔符为Linux路径分隔符便于统一处理
fileName = fileName.replace('\\', '/');
if (false == FileUtil.isWindows()
// 检查文件名中是否包含"/",不考虑以"/"结尾的情况
&& fileName.lastIndexOf(CharUtil.SLASH, fileName.length() - 2) > 0) {

View File

@@ -84,4 +84,11 @@ public class URLUtilTest {
String encode2 = URLUtil.encodeQuery(body);
Assert.assertEquals("366466+-+%E5%89%AF%E6%9C%AC.jpg", encode2);
}
@Test
public void getPathTest(){
String url = " http://www.aaa.bbb/search?scope=ccc&q=ddd";
String path = URLUtil.getPath(url);
Assert.assertEquals("/search", path);
}
}