mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复HttpUtil.normalizeParams
规则问题(issue#IBQIYQ@Gitee)
This commit is contained in:
parent
2046809264
commit
8d34a4d26e
@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.37(2025-03-03)
|
# 5.8.37(2025-03-07)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【json 】 ObjectMapper删除重复trim(pr#3859@Github)
|
* 【json 】 ObjectMapper删除重复trim(pr#3859@Github)
|
||||||
@ -16,6 +16,7 @@
|
|||||||
* 【setting】 修复`SettingLoader`load未抛出异常导致配置文件无法正常遍历的问题(pr#3868@Github)
|
* 【setting】 修复`SettingLoader`load未抛出异常导致配置文件无法正常遍历的问题(pr#3868@Github)
|
||||||
* 【cache 】 修复`ReentrantCache#getOrRemoveExpired`方法丢失onRemove触发问题(pr#1315@Gitee)
|
* 【cache 】 修复`ReentrantCache#getOrRemoveExpired`方法丢失onRemove触发问题(pr#1315@Gitee)
|
||||||
* 【json 】 修复`JsonUtil.toBean`泛型数组类型丢失问题(pr#3876@Github)
|
* 【json 】 修复`JsonUtil.toBean`泛型数组类型丢失问题(pr#3876@Github)
|
||||||
|
* 【http 】 修复`HttpUtil.normalizeParams`规则问题(issue#IBQIYQ@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.36(2025-02-18)
|
# 5.8.36(2025-02-18)
|
||||||
|
@ -9,11 +9,7 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.net.RFC3986;
|
import cn.hutool.core.net.RFC3986;
|
||||||
import cn.hutool.core.net.url.UrlQuery;
|
import cn.hutool.core.net.url.UrlQuery;
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.*;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import cn.hutool.core.util.ReUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.core.util.URLUtil;
|
|
||||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||||
import cn.hutool.http.server.SimpleServer;
|
import cn.hutool.http.server.SimpleServer;
|
||||||
|
|
||||||
@ -557,17 +553,17 @@ public class HttpUtil {
|
|||||||
pos = i + 1;
|
pos = i + 1;
|
||||||
}
|
}
|
||||||
} else if (c == '&') { // 参数对的分界点
|
} else if (c == '&') { // 参数对的分界点
|
||||||
if (pos != i) {
|
if (null == name) {
|
||||||
if (null == name) {
|
// 对于像&a&这类无参数值的字符串,我们将name为a的值设为""
|
||||||
// 对于像&a&这类无参数值的字符串,我们将name为a的值设为""
|
if(pos != i){
|
||||||
name = paramPart.substring(pos, i);
|
name = paramPart.substring(pos, i);
|
||||||
builder.append(RFC3986.QUERY_PARAM_NAME.encode(name, charset)).append('=');
|
builder.append(RFC3986.QUERY_PARAM_NAME.encode(name, charset)).append('=');
|
||||||
} else {
|
|
||||||
builder.append(RFC3986.QUERY_PARAM_NAME.encode(name, charset)).append('=')
|
|
||||||
.append(RFC3986.QUERY_PARAM_VALUE.encode(paramPart.substring(pos, i), charset)).append('&');
|
|
||||||
}
|
}
|
||||||
name = null;
|
} else {
|
||||||
|
builder.append(RFC3986.QUERY_PARAM_NAME.encode(name, charset)).append('=')
|
||||||
|
.append(RFC3986.QUERY_PARAM_VALUE.encode(paramPart.substring(pos, i), charset)).append('&');
|
||||||
}
|
}
|
||||||
|
name = null;
|
||||||
pos = i + 1;
|
pos = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package cn.hutool.http;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class IssueIBQIYQTest {
|
||||||
|
@Test
|
||||||
|
void normalizeParamsTest1() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("id", "");
|
||||||
|
map.put("type", "4");
|
||||||
|
String url = HttpUtil.toParams(map);
|
||||||
|
Assertions.assertEquals("id=&type=4", url);
|
||||||
|
url = HttpUtil.normalizeParams(url, null);
|
||||||
|
Assertions.assertEquals("id=&type=4", url);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user