mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
修复FileUtil.checkSlip方法缺陷
This commit is contained in:
parent
11655b0ad2
commit
d53ac71616
@ -3459,25 +3459,13 @@ public class FileUtil extends PathUtil {
|
||||
*/
|
||||
public static File checkSlip(File parentFile, File file) throws IllegalArgumentException {
|
||||
if (null != parentFile && null != file) {
|
||||
if (false == startsWith(parentFile, file)) {
|
||||
if (false == isSub(parentFile, file)) {
|
||||
throw new IllegalArgumentException("New file is outside of the parent dir: " + file.getName());
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查父文件是否为文件真正的父目录
|
||||
*
|
||||
* @param parentFile 父目录
|
||||
* @param file 文件
|
||||
* @return 是否为文件真正的父目录
|
||||
*/
|
||||
public static boolean startsWith(final File parentFile, final File file) {
|
||||
return PathUtil.toAbsNormal(parentFile.toPath())
|
||||
.startsWith(PathUtil.toAbsNormal(file.toPath()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件扩展名获得MimeType
|
||||
*
|
||||
|
@ -20,8 +20,14 @@ import java.util.List;
|
||||
*/
|
||||
public class FileUtilTest {
|
||||
|
||||
@Test
|
||||
public void fileTest1() {
|
||||
final File file = FileUtil.file("d:/aaa", "bbb");
|
||||
Assert.assertNotNull(file);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void fileTest() {
|
||||
public void fileTest2() {
|
||||
final File file = FileUtil.file("d:/aaa", "bbb");
|
||||
Assert.assertNotNull(file);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user