mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:20:07 +08:00
修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题
This commit is contained in:
parent
983eccf3e6
commit
9a6ac21798
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.28(2024-04-07)
|
||||
# 5.8.28(2024-04-08)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee)
|
||||
@ -10,6 +10,7 @@
|
||||
* 【extra 】 设置jsch登录认证方式,跳过Kerberos身份验证(pr#3530@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.27(2024-03-29)
|
||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.StreamProgress;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.RFC3986;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
@ -693,7 +694,8 @@ public class HttpUtil {
|
||||
* @return 合成后的URL
|
||||
*/
|
||||
public static String urlWithFormUrlEncoded(String url, Map<String, Object> form, Charset charset) {
|
||||
return urlWithForm(url, toParams(form, charset, true), charset, true);
|
||||
// issue#3536,urlWithForm会对参数进行一次编码,因此toParams无需编码
|
||||
return urlWithForm(url, toParams(form, null, false), charset, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
32
hutool-http/src/test/java/cn/hutool/http/Issue3536Test.java
Normal file
32
hutool-http/src/test/java/cn/hutool/http/Issue3536Test.java
Normal file
@ -0,0 +1,32 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Issue3536Test {
|
||||
|
||||
@Test
|
||||
public void urlWithFormUrlEncodedTest() {
|
||||
String url = "https://hutool.cn/test";
|
||||
final Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("redirect_uri", "https://api.hutool.cn/v1/test");
|
||||
paramMap.put("scope", "a,b,c你");
|
||||
|
||||
final String s = HttpUtil.urlWithFormUrlEncoded(url, paramMap, CharsetUtil.CHARSET_UTF_8);
|
||||
Assert.assertEquals("https://hutool.cn/test?scope=a,b,c%E4%BD%A0&redirect_uri=https://api.hutool.cn/v1/test", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toParamsTest() {
|
||||
final Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("redirect_uri", "https://api.hutool.cn/v1/test");
|
||||
paramMap.put("scope", "a,b,c你");
|
||||
|
||||
final String params = HttpUtil.toParams(paramMap, CharsetUtil.CHARSET_UTF_8, true);
|
||||
Assert.assertEquals("scope=a%2Cb%2Cc%E4%BD%A0&redirect_uri=https%3A%2F%2Fapi.hutool.cn%2Fv1%2Ftest", params);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user