mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add test
This commit is contained in:
@@ -2,6 +2,8 @@ package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -25,4 +27,19 @@ public class Issue2531Test {
|
||||
final HttpResponse execute = request.execute();
|
||||
Console.log(execute.body());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodePlusTest(){
|
||||
// 根据RFC3986规范,在URL中,"+"是安全字符,所以不会解码也不会编码
|
||||
UrlBuilder builder = UrlBuilder.ofHttp("https://hutool.cn/a=+");
|
||||
Assert.assertEquals("https://hutool.cn/a=+", builder.toString());
|
||||
|
||||
// 由于+为安全字符无需编码,ofHttp方法会把%2B解码为+,但是编码的时候不会编码
|
||||
builder = UrlBuilder.ofHttp("https://hutool.cn/a=%2B");
|
||||
Assert.assertEquals("https://hutool.cn/a=+", builder.toString());
|
||||
|
||||
// 如果你不想解码%2B,则charset传null表示不做解码,编码时候也被忽略
|
||||
builder = UrlBuilder.ofHttp("https://hutool.cn/a=%2B", null);
|
||||
Assert.assertEquals("https://hutool.cn/a=%2B", builder.toString());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user