mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix url bug
This commit is contained in:
parent
c0c71a5f8f
commit
ac5728d410
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.4.3 (2020-09-11)
|
||||
# 5.4.3 (2020-09-13)
|
||||
|
||||
### 新特性
|
||||
* 【core 】 使用静态的of方法来new对象(pr#177@Gitee)
|
||||
@ -12,6 +12,8 @@
|
||||
* 【core 】 扩充Console功能,支持可变参数(issue#1077@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复Dict.of错误(issue#I1UUO5@Gitee)
|
||||
* 【core 】 修复UrlBuilder地址参数问题(issue#I1UWCA@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -93,9 +93,9 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
|
||||
String key = null;
|
||||
for(int i = 0; i < keysAndValues.length; i++){
|
||||
if(i % 2 == 0){
|
||||
dict.put(key, keysAndValues[i]);
|
||||
} else{
|
||||
key = Convert.toStr(keysAndValues[i]);
|
||||
} else{
|
||||
dict.put(key, keysAndValues[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,18 @@ public final class UrlBuilder implements Serializable {
|
||||
return of(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getRawQuery(), uri.getFragment(), charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用URL字符串构建UrlBuilder,当传入的URL没有协议时,按照http协议对待<br>
|
||||
* 此方法不对URL编码
|
||||
*
|
||||
* @param httpUrl URL字符串
|
||||
* @return UrlBuilder
|
||||
* @since 5.4.3
|
||||
*/
|
||||
public static UrlBuilder ofHttpWithoutEncode(String httpUrl) {
|
||||
return ofHttp(httpUrl, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用URL字符串构建UrlBuilder,当传入的URL没有协议时,按照http协议对待。
|
||||
*
|
||||
|
@ -195,10 +195,10 @@ public class UrlQuery {
|
||||
}
|
||||
key = entry.getKey();
|
||||
if (StrUtil.isNotEmpty(key)) {
|
||||
sb.append(URLUtil.encodeAll(StrUtil.str(key), charset)).append("=");
|
||||
sb.append(URLUtil.encodeAll(StrUtil.str(key), charset));
|
||||
value = entry.getValue();
|
||||
if (StrUtil.isNotEmpty(value)) {
|
||||
sb.append(URLUtil.encodeAll(StrUtil.str(value), charset));
|
||||
if (null != value) {
|
||||
sb.append("=").append(URLUtil.encodeAll(StrUtil.str(value), charset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,8 +246,8 @@ public class UrlQuery {
|
||||
final String actualKey = URLUtil.decode(key, charset);
|
||||
this.query.put(actualKey, StrUtil.nullToEmpty(URLUtil.decode(value, charset)));
|
||||
} else if (null != value) {
|
||||
// name为空,value作为name,value赋值""
|
||||
this.query.put(URLUtil.decode(value, charset), StrUtil.EMPTY);
|
||||
// name为空,value作为name,value赋值null
|
||||
this.query.put(URLUtil.decode(value, charset), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,4 +30,17 @@ public class DictTest {
|
||||
Assert.assertEquals(1, dict.get("A"));
|
||||
Assert.assertEquals(1, dict.get("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofTest(){
|
||||
Dict dict = Dict.of(
|
||||
"RED", "#FF0000",
|
||||
"GREEN", "#00FF00",
|
||||
"BLUE", "#0000FF"
|
||||
);
|
||||
|
||||
Assert.assertEquals("#FF0000", dict.get("RED"));
|
||||
Assert.assertEquals("#00FF00", dict.get("GREEN"));
|
||||
Assert.assertEquals("#0000FF", dict.get("BLUE"));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -16,4 +17,13 @@ public class UrlQueryTest {
|
||||
Assert.assertEquals("111==", parse.get("b"));
|
||||
Assert.assertEquals("a=1&b=111==", parse.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofHttpWithoutEncodeTest(){
|
||||
// charset为null表示不做编码
|
||||
String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848";
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttpWithoutEncode(url);
|
||||
final String queryStr = urlBuilder.getQueryStr();
|
||||
Assert.assertEquals("imageMogr2/auto-orient/thumbnail/500&pid=259848", queryStr);
|
||||
}
|
||||
}
|
||||
|
@ -133,4 +133,14 @@ public class HttpRequestTest {
|
||||
HttpRequest request = HttpUtil.createGet("http://localhost:8888/get");
|
||||
Console.log(request.execute().body());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getWithoutEncodeTest(){
|
||||
String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848";
|
||||
HttpRequest get = HttpUtil.createGet(url);
|
||||
Console.log(get.getUrl());
|
||||
HttpResponse execute = get.execute();
|
||||
Console.log(execute.body());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user