fix UrlBuilder bug

This commit is contained in:
Looly
2021-01-21 12:36:05 +08:00
parent 856e7a3e13
commit b7ca34d0e8
6 changed files with 74 additions and 26 deletions

View File

@@ -6,6 +6,10 @@ import cn.hutool.core.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
public class UrlBuilderTest {
@Test
@@ -217,4 +221,18 @@ public class UrlBuilderTest {
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("https://hutool.cn//file/test.jpg", CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("https://hutool.cn//file/test.jpg", urlBuilder.toString());
}
@Test
public void toURITest() throws URISyntaxException {
String webUrl = "http://exmple.com/patha/pathb?a=123"; // 报错数据
final UrlBuilder urlBuilder = UrlBuilder.of(webUrl, StandardCharsets.UTF_8);
Assert.assertEquals(new URI(webUrl), urlBuilder.toURI());
}
@Test
public void testEncodeInQuery() {
String webUrl = "http://exmple.com/patha/pathb?a=123&b=4?6&c=789"; // b=4?6 参数中有未编码的?
final UrlBuilder urlBuilder = UrlBuilder.of(webUrl, StandardCharsets.UTF_8);
Assert.assertEquals("a=123&b=4%3F6&c=789", urlBuilder.getQueryStr());
}
}