修复getFileNameFromDisposition不符合规范问题

This commit is contained in:
Looly 2024-08-15 18:27:02 +08:00
parent 67b8bc1332
commit 050c379b3f
2 changed files with 29 additions and 4 deletions

View File

@ -7,6 +7,7 @@
### 🐣新特性 ### 🐣新特性
### 🐞Bug修复 ### 🐞Bug修复
* 【http 】 修复getFileNameFromDisposition不符合规范问题issue#IAKBPD@Gitee
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.8.31(2024-08-12) # 5.8.31(2024-08-12)

View File

@ -504,7 +504,6 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
} }
// ---------------------------------------------------------------- Private method start // ---------------------------------------------------------------- Private method start
/** /**
* 从Content-Disposition头中获取文件名 * 从Content-Disposition头中获取文件名
* *
@ -513,14 +512,39 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
* @return 文件名empty表示无 * @return 文件名empty表示无
*/ */
private static String getFileNameFromDispositions(final List<String> dispositions, String paramName) { private static String getFileNameFromDispositions(final List<String> dispositions, String paramName) {
// 正则转义
paramName = StrUtil.replace(paramName, "*", "\\*");
String fileName = null; String fileName = null;
for (String disposition : dispositions) { for (final String disposition : dispositions) {
fileName = ReUtil.getGroup1(paramName + "=\"(.*?)\"", disposition); fileName = ReUtil.getGroup1(paramName + "=([^;]+)", disposition);
if (StrUtil.isNotBlank(fileName)) { if (StrUtil.isNotBlank(fileName)) {
break; break;
} }
} }
return fileName; return getRfc5987Value(fileName);
}
/**
* 获取rfc5987标准的值标准见https://www.rfc-editor.org/rfc/rfc5987#section-3.2.1<br>
* 包括
*
*<ul>
* <li>Non-extended无双引号包裹的值</li>
* <li>Non-extended双引号包裹的值</li>
* <li>Extended notation编码'语言'</li>
*</ul>
*
* @param value
* @return 结果值
*/
private static String getRfc5987Value(final String value){
final List<String> split = StrUtil.split(value, '\'');
if(3 == split.size()){
return split.get(2);
}
// 普通值
return StrUtil.unWrap(value, '"');
} }
/** /**