This commit is contained in:
Looly
2022-09-18 11:58:46 +08:00
parent 0e287161bd
commit 68cfc3db5d
2 changed files with 17 additions and 5 deletions

View File

@@ -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());
}
}