mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix bug
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user