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