mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 12:18:01 +08:00
normalize support samba path
This commit is contained in:
parent
a8e9de0ffb
commit
30d26ab22d
@ -11,6 +11,7 @@
|
||||
* 【core】 TimeInterval增加intervalPretty方法(issue#I12A6T@Gitee)
|
||||
* 【core】 改进ArrayUtil.toString,提高性能
|
||||
* 【system】 增加SystemPropsKeys(issue#550@Github)
|
||||
* 【core】 FileUtil.normalize在win下支持samba路径(issue#549@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【core】 修复DateUtil.offset导致的时区错误问题(issue#I1294O@Gitee)
|
||||
@ -18,6 +19,7 @@
|
||||
* 【db】 修复StatementUtil.getGeneratedKeys返回主键数量不足问题
|
||||
* 【db】 修复锁的问题(issue#546@Github)
|
||||
* 【db】 修复CombinationAnnotationElement问题(issue#547@Github)
|
||||
* 【core】 修复Validator.isGeneral问题
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -48,6 +48,7 @@ import cn.hutool.core.io.file.LineSeparator;
|
||||
import cn.hutool.core.io.file.Tailer;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
@ -1576,15 +1577,20 @@ public class FileUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// 兼容Spring风格的ClassPath路径,去除前缀,不区分大小写
|
||||
String pathToUse = StrUtil.removePrefixIgnoreCase(path, URLUtil.CLASSPATH_URL_PREFIX);
|
||||
// 去除file:前缀
|
||||
pathToUse = StrUtil.removePrefixIgnoreCase(pathToUse, URLUtil.FILE_URL_PREFIX);
|
||||
// 统一使用斜杠
|
||||
pathToUse = pathToUse.replaceAll("[/\\\\]{1,}", StrUtil.SLASH).trim();
|
||||
//兼容Windows下的共享目录路径(原始路径如果以\\开头,则保留这种路径)
|
||||
if(path.startsWith("\\\\")){
|
||||
pathToUse = "\\" + pathToUse;
|
||||
}
|
||||
|
||||
int prefixIndex = pathToUse.indexOf(StrUtil.COLON);
|
||||
String prefix = "";
|
||||
int prefixIndex = pathToUse.indexOf(StrUtil.COLON);
|
||||
if (prefixIndex > -1) {
|
||||
// 可能Windows风格路径
|
||||
prefix = pathToUse.substring(0, prefixIndex + 1);
|
||||
|
@ -371,10 +371,10 @@ public class Validator {
|
||||
* @return 是否为给定长度范围的英文字母 、数字和下划线
|
||||
*/
|
||||
public static boolean isGeneral(CharSequence value, int min, int max) {
|
||||
String reg = "^\\w{" + min + "," + max + "}$";
|
||||
if (min < 0) {
|
||||
min = 0;
|
||||
}
|
||||
String reg = "^\\w{" + min + "," + max + "}$";
|
||||
if (max <= 0) {
|
||||
reg = "^\\w{" + min + ",}$";
|
||||
}
|
||||
|
@ -136,6 +136,8 @@ public class FileUtilTest {
|
||||
Assert.assertEquals("bar", FileUtil.normalize("~/../bar"));
|
||||
Assert.assertEquals("bar", FileUtil.normalize("../../bar"));
|
||||
Assert.assertEquals("C:/bar", FileUtil.normalize("/C:/bar"));
|
||||
|
||||
Assert.assertEquals("\\/192.168.1.1/Share/", FileUtil.normalize("\\\\192.168.1.1\\Share\\"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -8,11 +8,11 @@ import cn.hutool.core.lang.Validator;
|
||||
|
||||
/**
|
||||
* 验证器单元测试
|
||||
* @author Looly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class ValidatorTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void isNumberTest() {
|
||||
Assert.assertTrue(Validator.isNumber("45345365465"));
|
||||
@ -20,35 +20,35 @@ public class ValidatorTest {
|
||||
Assert.assertTrue(Validator.isNumber("5.222"));
|
||||
Assert.assertTrue(Validator.isNumber("0.33323"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isLetterTest() {
|
||||
Assert.assertTrue(Validator.isLetter("asfdsdsfds"));
|
||||
Assert.assertTrue(Validator.isLetter("asfdsdfdsfVCDFDFGdsfds"));
|
||||
Assert.assertTrue(Validator.isLetter("asfdsdf你好dsfVCDFDFGdsfds"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isUperCaseTest() {
|
||||
Assert.assertTrue(Validator.isUpperCase("VCDFDFG"));
|
||||
Assert.assertTrue(Validator.isUpperCase("ASSFD"));
|
||||
|
||||
|
||||
Assert.assertFalse(Validator.isUpperCase("asfdsdsfds"));
|
||||
Assert.assertFalse(Validator.isUpperCase("ASSFD你好"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isLowerCaseTest() {
|
||||
Assert.assertTrue(Validator.isLowerCase("asfdsdsfds"));
|
||||
|
||||
|
||||
Assert.assertFalse(Validator.isLowerCase("aaaa你好"));
|
||||
Assert.assertFalse(Validator.isLowerCase("VCDFDFG"));
|
||||
Assert.assertFalse(Validator.isLowerCase("ASSFD"));
|
||||
Assert.assertFalse(Validator.isLowerCase("ASSFD你好"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isBirthdayTest(){
|
||||
public void isBirthdayTest() {
|
||||
boolean b = Validator.isBirthday("20150101");
|
||||
Assert.assertTrue(b);
|
||||
boolean b2 = Validator.isBirthday("2015-01-01");
|
||||
@ -61,7 +61,7 @@ public class ValidatorTest {
|
||||
Assert.assertTrue(b5);
|
||||
boolean b6 = Validator.isBirthday("2018-08-15");
|
||||
Assert.assertTrue(b6);
|
||||
|
||||
|
||||
//验证年非法
|
||||
Assert.assertFalse(Validator.isBirthday("2095.05.01"));
|
||||
//验证月非法
|
||||
@ -69,18 +69,18 @@ public class ValidatorTest {
|
||||
//验证日非法
|
||||
Assert.assertFalse(Validator.isBirthday("2015.02.29"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isCitizenIdTest(){
|
||||
public void isCitizenIdTest() {
|
||||
boolean b = Validator.isCitizenId("150218199012123389");
|
||||
Assert.assertTrue(b);
|
||||
}
|
||||
|
||||
@Test(expected=ValidateException.class)
|
||||
public void validateTest() throws ValidateException{
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
public void validateTest() throws ValidateException {
|
||||
Validator.validateChinese("我是一段zhongwen", "内容中包含非中文");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isEmailTest() {
|
||||
boolean email = Validator.isEmail("abc_cde@163.com");
|
||||
@ -94,7 +94,7 @@ public class ValidatorTest {
|
||||
boolean email4 = Validator.isEmail("xiaolei.Lu@aaa.b");
|
||||
Assert.assertTrue(email4);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isMobileTest() {
|
||||
boolean m1 = Validator.isMobile("13900221432");
|
||||
@ -104,16 +104,32 @@ public class ValidatorTest {
|
||||
boolean m3 = Validator.isMobile("+8618600221432");
|
||||
Assert.assertTrue(m3);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isMatchTest() {
|
||||
String url = "http://aaa-bbb.somthing.com/a.php?a=b&c=2";
|
||||
Assert.assertTrue(Validator.isMactchRegex(PatternPool.URL_HTTP, url));
|
||||
|
||||
|
||||
url = "https://aaa-bbb.somthing.com/a.php?a=b&c=2";
|
||||
Assert.assertTrue(Validator.isMactchRegex(PatternPool.URL_HTTP, url));
|
||||
|
||||
|
||||
url = "https://aaa-bbb.somthing.com:8080/a.php?a=b&c=2";
|
||||
Assert.assertTrue(Validator.isMactchRegex(PatternPool.URL_HTTP, url));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isGeneralTest() {
|
||||
String str = "";
|
||||
boolean general = Validator.isGeneral(str, -1, 5);
|
||||
Assert.assertTrue(general);
|
||||
|
||||
str = "123_abc_ccc";
|
||||
general = Validator.isGeneral(str, -1, 100);
|
||||
Assert.assertTrue(general);
|
||||
|
||||
// 不允许中文
|
||||
str = "123_abc_ccc中文";
|
||||
general = Validator.isGeneral(str, -1, 100);
|
||||
Assert.assertFalse(general);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user