From cb86921c1ba436604b8928579b70d642b57f2745 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 17 Feb 2023 14:15:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgit=E6=96=87=E4=BB=B6=E6=97=A0=E6=B3=95pull?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=90=8C=E6=97=B6=E5=9C=A8?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6=E6=96=B9=E6=B3=95=E4=B8=8A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1023211 --user=宋天阳 【项目管理】文件管理 - git文件详情 - 关联用例,pull文件失败 https://www.tapd.cn/55049933/s/1336948 --- .../java/io/metersphere/commons/utils/FileUtils.java | 10 +++++++--- .../java/io/metersphere/service/ResourceService.java | 8 +++----- .../metersphere/remote/service/ApiRelateService.java | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java index 1dd32da6c6..f5e4461c46 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java @@ -34,9 +34,13 @@ public class FileUtils { public static final String ATTACHMENT_DIR = "/opt/metersphere/data/attachment"; public static final String ATTACHMENT_TMP_DIR = "/opt/metersphere/data/attachment/tmp"; - public static void validateFileName(String fileName) { - if (StringUtils.isNotEmpty(fileName) && StringUtils.contains(fileName, "." + File.separator)) { - MSException.throwException(Translator.get("invalid_parameter")); + public static void validateFileName(String... fileNames) { + if (fileNames != null) { + for (String fileName : fileNames) { + if (StringUtils.isNotEmpty(fileName) && StringUtils.contains(fileName, "." + File.separator)) { + MSException.throwException(Translator.get("invalid_parameter")); + } + } } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ResourceService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ResourceService.java index 826f9e2dd8..c1d1ab03b3 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ResourceService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/ResourceService.java @@ -5,6 +5,7 @@ import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.LogUtil; import io.metersphere.i18n.Translator; import io.metersphere.request.MdUploadRequest; +import jakarta.annotation.Resource; import org.springframework.core.io.FileSystemResource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -14,7 +15,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; -import jakarta.annotation.Resource; import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -43,10 +43,8 @@ public class ResourceService { } public ResponseEntity getUiResultImage(String name, String reportId) { - if (name.contains("/")) { - MSException.throwException(Translator.get("invalid_parameter")); - } - return getImage(FileUtils.UI_IMAGE_DIR + "/" + reportId + "/" + name); + FileUtils.validateFileName(name, reportId); + return getImage(FileUtils.UI_IMAGE_DIR + File.separator + reportId + File.separator + name); } public ResponseEntity getImage(String path) { diff --git a/project-management/backend/src/main/java/io/metersphere/remote/service/ApiRelateService.java b/project-management/backend/src/main/java/io/metersphere/remote/service/ApiRelateService.java index 40b81c60ff..cda1f2c998 100644 --- a/project-management/backend/src/main/java/io/metersphere/remote/service/ApiRelateService.java +++ b/project-management/backend/src/main/java/io/metersphere/remote/service/ApiRelateService.java @@ -76,7 +76,7 @@ public class ApiRelateService { if (CollectionUtils.isNotEmpty(requestList)) { try { microService.postForData(MicroServiceName.API_TEST, - "/api/definition/update/file/", + "/api/definition/update/file", requestList); } catch (Exception e) { LogUtil.error(e);