修复FileUtil无法正确识别Smb网络存储的路径问题

This commit is contained in:
Looly 2023-08-10 22:03:16 +08:00
parent d2beedbf78
commit e58a6055d6
4 changed files with 53 additions and 5 deletions

View File

@ -16,6 +16,7 @@
* 【core 】 修复PathUtil.moveContent当target不存在时会报错问题issue#3238@Github
* 【db 】 修复SqlUtil.formatSql 格式化的sql换行异常pr#3247@Github
* 【core 】 修复DateUtil.parse 给定一个时间解析错误问题issue#I7QI6R@Gitee
* 【core 】 修复FileUtil无法正确识别Smb网络存储的路径问题issue#3253@Github
-------------------------------------------------------------------------------------------------------------
# 5.8.21(2023-07-29)

View File

@ -1607,6 +1607,11 @@ public class FileUtil extends PathUtil {
return null;
}
//兼容Windows下的共享目录路径原始路径如果以\\开头则保留这种路径
if (path.startsWith("\\\\")) {
return path;
}
// 兼容Spring风格的ClassPath路径去除前缀不区分大小写
String pathToUse = StrUtil.removePrefixIgnoreCase(path, URLUtil.CLASSPATH_URL_PREFIX);
// 去除file:前缀
@ -1621,10 +1626,6 @@ public class FileUtil extends PathUtil {
pathToUse = pathToUse.replaceAll("[/\\\\]+", StrUtil.SLASH);
// 去除开头空白符末尾空白符合法不去除
pathToUse = StrUtil.trimStart(pathToUse);
//兼容Windows下的共享目录路径原始路径如果以\\开头则保留这种路径
if (path.startsWith("\\\\")) {
pathToUse = "\\" + pathToUse;
}
String prefix = StrUtil.EMPTY;
int prefixIndex = pathToUse.indexOf(StrUtil.COLON);

View File

@ -182,7 +182,9 @@ 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\\"));
// issue#3253smb保留格式
Assert.assertEquals("\\\\192.168.1.1\\Share\\", FileUtil.normalize("\\\\192.168.1.1\\Share\\"));
}
@Test

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package cn.hutool.extra.qrcode;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Console;
import org.junit.Ignore;
import org.junit.Test;
import java.awt.Color;
import java.io.File;
public class IssueI7RUIVTest {
@Test
@Ignore
public void generateTest() {
final QrConfig config = new QrConfig(300, 300);
// 设置前景色既二维码颜色青色
config.setForeColor(Color.CYAN);
// 设置背景色灰色
config.setBackColor(Color.GRAY);
// 生成二维码到文件也可以到流
final File file = QrCodeUtil.generate("https://hutool.cn/", config, FileUtil.file("d:/test/qrcode.jpg"));
// 识别二维码
// decode -> "http://hutool.cn/"
final String decode = QrCodeUtil.decode(ImgUtil.read("d:/test/qrcode.jpg"), true, true);
Console.log("decode info = " + decode);
}
}