From 26751fac57f80459cea9e7ec8ba0a960c695e728 Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 24 Aug 2023 08:56:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D302=E9=87=8D=E5=AE=9A?= =?UTF-8?q?=E5=90=91=E6=97=B6=EF=BC=8CLocation=E4=B8=AD=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E5=8F=B7=E8=A2=AB=E8=BD=AC=E4=B9=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++- .../main/java/cn/hutool/http/HttpRequest.java | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9149ea59c..5a827b4bc 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.22(2023-08-21) +# 5.8.22(2023-08-24) ### 🐣新特性 * 【core 】 NumberUtil.nullToZero增加重载(issue#I7PPD2@Gitee) @@ -23,6 +23,7 @@ * 【core 】 修复FieldsComparator比较结果不正确问题(issue#3259@Github) * 【core 】 修复Db.findAll全局忽略大小写无效问题(issue#I7T30Y@Gitee) * 【core 】 修复Ipv4Util.getEndIpLong 取反符号导致数据越界(issue#I7U1OQ@Gitee) +* 【http 】 修复302重定向时,Location中的问号被转义问题(issue#3265@Github) ------------------------------------------------------------------------------------------------------------- # 5.8.21(2023-07-29) diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java index c46df6120..9c9f8ed2b 100755 --- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java @@ -1293,13 +1293,23 @@ public class HttpRequest extends HttpBase { final UrlBuilder redirectUrl; String location = httpConnection.header(Header.LOCATION); if (false == HttpUtil.isHttp(location) && false == HttpUtil.isHttps(location)) { - // issue#I5TPSY - // location可能为相对路径 + // issue#I5TPSY, location可能为相对路径 if (false == location.startsWith("/")) { location = StrUtil.addSuffixIfNot(this.url.getPathStr(), "/") + location; } + + // issue#3265, 相对路径中可能存在参数,单独处理参数 + final String query; + final List split = StrUtil.split(location, '?', 2); + if (split.size() == 2) { + // 存在参数 + location = split.get(0); + query = split.get(1); + } else { + query = null; + } redirectUrl = UrlBuilder.of(this.url.getScheme(), this.url.getHost(), this.url.getPort() - , location, null, null, this.charset); + , location, query, null, this.charset); } else { redirectUrl = UrlBuilder.ofHttpWithoutEncode(location); }