mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-02 20:02:49 +08:00
fix null bug
This commit is contained in:
parent
fbeb5ab28b
commit
569877e0ef
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.8.0.M3 (2022-04-08)
|
||||
# 5.8.0.M3 (2022-04-10)
|
||||
|
||||
### ❌不兼容特性
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
* 【core 】 修复UserAgentUtil识别Linux出错(issue#I50YGY@Gitee)
|
||||
* 【poi 】 修复ExcelWriter.getDisposition方法生成错误(issue#2239@Github)
|
||||
* 【core 】 修复UrlBuilder重复编码的问题(issue#2243@Github)
|
||||
* 【http 】 修复HttpRequest中urlQuery,处理get请求参数的时候会导致空指针异常(pr#2248@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -371,9 +371,10 @@ public final class UrlBuilder implements Builder<String> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询语句,例如a=1&b=2
|
||||
* 获取查询语句,例如a=1&b=2<br>
|
||||
* 可能为{@code null}
|
||||
*
|
||||
* @return 查询语句,例如a=1&b=2
|
||||
* @return 查询语句,例如a=1&b=2,可能为{@code null}
|
||||
*/
|
||||
public UrlQuery getQuery() {
|
||||
return query;
|
||||
|
@ -139,6 +139,13 @@ public class UrlBuilderTest {
|
||||
Assert.assertEquals("frag1", builder.getFragment());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofNullQueryTest() {
|
||||
final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb", CharsetUtil.CHARSET_UTF_8);
|
||||
Assert.assertNotNull(builder.getQuery());
|
||||
Assert.assertNull(builder.getQuery().get("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWithChineseTest() {
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp("www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
|
||||
|
@ -1174,15 +1174,17 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
*/
|
||||
private void urlWithParamIfGet() {
|
||||
if (Method.GET.equals(method) && false == this.isRest && this.redirectCount <= 0) {
|
||||
if (this.url.getQuery() == null) {
|
||||
this.url.setQuery(new UrlQuery());
|
||||
UrlQuery query = this.url.getQuery();
|
||||
if (null == query) {
|
||||
query = new UrlQuery();
|
||||
this.url.setQuery(query);
|
||||
}
|
||||
|
||||
// 优先使用body形式的参数,不存在使用form
|
||||
if (ArrayUtil.isNotEmpty(this.bodyBytes)) {
|
||||
this.url.getQuery().parse(StrUtil.str(this.bodyBytes, this.charset), this.charset);
|
||||
query.parse(StrUtil.str(this.bodyBytes, this.charset), this.charset);
|
||||
} else {
|
||||
this.url.getQuery().addAll(this.form);
|
||||
query.addAll(this.form);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.net.SSLProtocols;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
@ -198,12 +197,11 @@ public class HttpRequestTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void urlWithParamIfGet(){
|
||||
public void urlWithParamIfGetTest(){
|
||||
UrlBuilder urlBuilder = new UrlBuilder();
|
||||
urlBuilder.setScheme("https").setHost("hutool.cn");
|
||||
|
||||
HttpRequest httpRequest = new HttpRequest(urlBuilder);
|
||||
httpRequest.setMethod(Method.GET);
|
||||
HttpResponse httpResponse = httpRequest.execute();
|
||||
httpRequest.setMethod(Method.GET).execute();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user