fix(项目管理): 修复git文件无法pull的问题,同时在获取文件方法上增加校验判断

--bug=1023211 --user=宋天阳 【项目管理】文件管理 - git文件详情 -
关联用例,pull文件失败
https://www.tapd.cn/55049933/s/1336948
This commit is contained in:
song-tianyang 2023-02-17 14:15:48 +08:00 committed by fit2-zhao
parent 012a38c3f3
commit cb86921c1b
3 changed files with 11 additions and 9 deletions

View File

@ -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"));
}
}
}
}

View File

@ -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<FileSystemResource> 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<FileSystemResource> getImage(String path) {

View File

@ -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);