From 77fc18b6f7207be08539cd7e22441a7bcc1626cb Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 26 Sep 2023 14:51:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=96=87=E4=BB=B6=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E6=A0=A1=E9=AA=8C=EF=BC=8C=E9=98=B2=E6=AD=A2=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E7=A9=BF=E8=B6=8A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/metersphere/sdk/file/LocalFileRepository.java | 3 +++ .../sdk/src/main/java/io/metersphere/sdk/util/MsFileUtils.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java index 3969a1dcc3..4cebee74b9 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java @@ -57,6 +57,7 @@ public class LocalFileRepository implements FileRepository { @Override public void deleteFolder(FileRequest request) throws Exception { + MsFileUtils.validateFileName(request.getProjectId(), request.getFileName()); this.delete(request); } @@ -81,10 +82,12 @@ public class LocalFileRepository implements FileRepository { } private String getFilePath(FileRequest request) { + MsFileUtils.validateFileName(request.getProjectId(), request.getFileName()); return StringUtils.join(getFileDir(request), "/", request.getFileName()); } private String getFileDir(FileRequest request) { + MsFileUtils.validateFileName(request.getProjectId(), request.getFileName()); return StringUtils.join(MsFileUtils.DATE_ROOT_DIR, "/", request.getProjectId()); } } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/MsFileUtils.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/MsFileUtils.java index 37399e00ad..949287b0a9 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/MsFileUtils.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/MsFileUtils.java @@ -14,7 +14,7 @@ public class MsFileUtils { public static void validateFileName(String... fileNames) { if (fileNames != null) { for (String fileName : fileNames) { - if (StringUtils.isNotEmpty(fileName) && StringUtils.contains(fileName, "." + File.separator)) { + if (StringUtils.isNotBlank(fileName) && StringUtils.contains(fileName, "." + File.separator)) { throw new MSException(Translator.get("invalid_parameter")); } }