mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add Paillier
This commit is contained in:
@@ -2638,18 +2638,7 @@ public class FileUtil extends PathUtil {
|
||||
*/
|
||||
public static File checkSlip(final File parentFile, final File file) throws IllegalArgumentException {
|
||||
if (null != parentFile && null != file) {
|
||||
String parentCanonicalPath;
|
||||
String canonicalPath;
|
||||
try {
|
||||
parentCanonicalPath = parentFile.getCanonicalPath();
|
||||
canonicalPath = file.getCanonicalPath();
|
||||
} catch (final IOException e) {
|
||||
// issue#I4CWMO@Gitee
|
||||
// getCanonicalPath有时会抛出奇怪的IO异常,此时忽略异常,使用AbsolutePath判断。
|
||||
parentCanonicalPath = parentFile.getAbsolutePath();
|
||||
canonicalPath = file.getAbsolutePath();
|
||||
}
|
||||
if (!canonicalPath.startsWith(parentCanonicalPath)) {
|
||||
if(!file.toPath().startsWith(parentFile.toPath())){
|
||||
throw new IllegalArgumentException("New file is outside of the parent dir: " + file.getName());
|
||||
}
|
||||
}
|
||||
|
@@ -494,4 +494,11 @@ public class FileUtilTest {
|
||||
final byte[] bytes = FileUtil.readBytes("test.properties");
|
||||
Assertions.assertEquals(125, bytes.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkSlipTest() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
||||
FileUtil.checkSlip(FileUtil.file("test/a"), FileUtil.file("test/../a"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user