From c68b65157b511a4bad10a4523ecc5385f0652272 Mon Sep 17 00:00:00 2001 From: luorui Date: Wed, 3 Jul 2024 15:23:25 +0800 Subject: [PATCH] =?UTF-8?q?hotfix:HttpResponseProxy#extractFileNameFromCon?= =?UTF-8?q?tentString=20=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8D=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5:https://gitee.com/binary/weixin-java-tools/issues/IA7?= =?UTF-8?q?FND?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/common/util/http/HttpResponseProxy.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java index f338ece67..3e0acb46f 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java @@ -1,15 +1,11 @@ package me.chanjar.weixin.common.util.http; import jodd.http.HttpResponse; -import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; import okhttp3.Response; import org.apache.http.Header; import org.apache.http.client.methods.CloseableHttpResponse; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - /** *
  * 三种http框架的response代理类,方便提取公共方法
@@ -19,7 +15,6 @@ import java.util.regex.Pattern;
  * @author Binary Wang
  */
 public class HttpResponseProxy {
-  private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\"");
 
   private CloseableHttpResponse apacheHttpResponse;
   private HttpResponse joddHttpResponse;
@@ -79,9 +74,11 @@ public class HttpResponseProxy {
       throw new WxErrorException("无法获取到文件名,content为空");
     }
 
-    Matcher m = PATTERN.matcher(content);
-    if (m.matches()) {
-      return m.group(1);
+    int startIndex = content.indexOf("filename=\"");
+    if (startIndex != -1) {
+      startIndex += "filename=\"".length();
+      int endIndex = content.indexOf('"', startIndex);
+      return content.substring(startIndex, endIndex);
     }
 
     throw new WxErrorException("无法获取到文件名,header信息有问题");
-- 
Gitee