mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix normalize
This commit is contained in:
parent
4ab60ad7b8
commit
e3810b3727
@ -3,11 +3,12 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.6.7 (2021-05-27)
|
||||
# 5.6.7 (2021-05-28)
|
||||
|
||||
### 🐣新特性
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复FileUtil.normalize去掉末尾空格问题(issue#1603@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -1415,7 +1415,6 @@ public class FileUtil extends PathUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// 兼容Spring风格的ClassPath路径,去除前缀,不区分大小写
|
||||
String pathToUse = StrUtil.removePrefixIgnoreCase(path, URLUtil.CLASSPATH_URL_PREFIX);
|
||||
// 去除file:前缀
|
||||
@ -1427,13 +1426,15 @@ public class FileUtil extends PathUtil {
|
||||
}
|
||||
|
||||
// 统一使用斜杠
|
||||
pathToUse = pathToUse.replaceAll("[/\\\\]+", StrUtil.SLASH).trim();
|
||||
pathToUse = pathToUse.replaceAll("[/\\\\]+", StrUtil.SLASH);
|
||||
// 去除开头空白符,末尾空白符合法,不去除
|
||||
pathToUse = StrUtil.trimStart(pathToUse);
|
||||
//兼容Windows下的共享目录路径(原始路径如果以\\开头,则保留这种路径)
|
||||
if (path.startsWith("\\\\")) {
|
||||
pathToUse = "\\" + pathToUse;
|
||||
}
|
||||
|
||||
String prefix = "";
|
||||
String prefix = StrUtil.EMPTY;
|
||||
int prefixIndex = pathToUse.indexOf(StrUtil.COLON);
|
||||
if (prefixIndex > -1) {
|
||||
// 可能Windows风格路径
|
||||
|
@ -158,10 +158,14 @@ public class FileUtilTest {
|
||||
Assert.assertEquals("bar", FileUtil.normalize("../../bar"));
|
||||
Assert.assertEquals("C:/bar", FileUtil.normalize("/C:/bar"));
|
||||
Assert.assertEquals("C:", FileUtil.normalize("C:"));
|
||||
|
||||
Assert.assertEquals("\\/192.168.1.1/Share/", FileUtil.normalize("\\\\192.168.1.1\\Share\\"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeBlankTest() {
|
||||
Assert.assertEquals("C:/aaa ", FileUtil.normalize("C:\\aaa "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeHomePathTest() {
|
||||
String home = FileUtil.getUserHomePath().replace('\\', '/');
|
||||
|
Loading…
x
Reference in New Issue
Block a user