修复流的方法错误 ,修复跨域脚本缺少BASE64 (#423)

* 修复office下载方法中 错误

* 更新OFD解析效果,修复禁止trace请求无效问题,其他压缩包修复

* 修复压缩包 缓存BUG

* 限制某些特殊文件上传

* 修复OFFICE文件密码检查关闭流 上传文件关闭流 检查PDF文件是否存在

* 特殊符号的支持

Co-authored-by: gaoxiongzaq <admin@cxcp.com>
This commit is contained in:
gaoxingzaq
2023-01-11 13:26:18 +08:00
committed by GitHub
parent 04401ee600
commit 5dc543db99
16 changed files with 918 additions and 752 deletions

View File

@ -50,6 +50,11 @@ public class DownloadUtils {
response.setMsg("下载失败:文件名不合法!" + urlStr);
return response;
}
if(realPath.equals("cunzhai")){
response.setContent(fileDir + fileName);
response.setMsg(fileName);
return response;
}
try {
URL url = WebUtils.normalizedURL(urlStr);
if (!fileAttribute.getSkipDownLoad()) {
@ -110,6 +115,7 @@ public class DownloadUtils {
File realFile = new File(realPath);
if (realFile.exists()) {
fileAttribute.setSkipDownLoad(true);
return "cunzhai";
}
return realPath;
}

View File

@ -102,7 +102,7 @@ public class KkFileUtils {
public static String htmlEscape(String input) {
if(StringUtils.hasText(input)){
//input = input.replaceAll("\\{", "%7B").replaceAll("}", "%7D").replaceAll("\\\\", "%5C");
return HtmlUtils.htmlEscape(input);
return HtmlUtils.htmlEscape(input, "UTF-8");
}
return input;
}

View File

@ -7,6 +7,7 @@ import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.springframework.lang.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
@ -27,8 +28,10 @@ public class OfficeUtils {
* @return 是否受密码保护
*/
public static boolean isPwdProtected(String path) {
InputStream propStream = null;
try {
ExtractorFactory.createExtractor(Files.newInputStream(Paths.get(path)));
propStream = Files.newInputStream(Paths.get(path));
ExtractorFactory.createExtractor(propStream);
} catch (IOException | EncryptedDocumentException e) {
if (e.getMessage().toLowerCase().contains(POI_INVALID_PASSWORD_MSG)) {
return true;
@ -42,10 +45,17 @@ public class OfficeUtils {
}
}
}
}finally {
if(propStream!=null) {//如果文件输入流不是null
try {
propStream.close();//关闭文件输入流
} catch (IOException e) {
e.printStackTrace();
}
}
}
return false;
}
/**
* 判断office文件是否可打开兼容
*
@ -54,15 +64,24 @@ public class OfficeUtils {
* @return 是否可打开(兼容)
*/
public static synchronized boolean isCompatible(String path, @Nullable String password) {
InputStream propStream = null;
try {
propStream = Files.newInputStream(Paths.get(path));
Biff8EncryptionKey.setCurrentUserPassword(password);
ExtractorFactory.createExtractor(Files.newInputStream(Paths.get(path)));
ExtractorFactory.createExtractor(propStream);
} catch (Exception e) {
return false;
} finally {
Biff8EncryptionKey.setCurrentUserPassword(null);
if(propStream!=null) {//如果文件输入流不是null
try {
propStream.close();//关闭文件输入流
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
}
}

View File

@ -131,6 +131,11 @@ public class WebUtils {
} catch (UnsupportedEncodingException e) {
return null;
}
String urlStrr = url.toLowerCase(); //转换为小写对比
boolean wjl =kuayu("&fullfilename=", urlStrr); //判断是否启用文件流
if(wjl){
url = url.substring(0,url.lastIndexOf("&")); //删除添加的文件流内容
}
String noQueryUrl = url.substring(0, url.indexOf("?"));
String parameterStr = url.substring(url.indexOf("?"));
parameterStr = parameterStr.replaceFirst(fullFileName, encodedFileName);