2026-06-30 24681c81c09022f584a57006f2534b5f74723414
yudao-framework/yudao-common/src/test/java/cn/iocoder/yudao/framework/common/util/http/HttpUtilsTest.java
@@ -10,6 +10,36 @@
public class HttpUtilsTest {
    @Test
    public void testEncodeUrlPath() {
        // 准备参数
        String path = "avatar/中文 100%+文件.jpg";
        // 调用
        String result = HttpUtils.encodeUrlPath(path);
        // 断言
        assertEquals("avatar/%E4%B8%AD%E6%96%87%20100%25+%E6%96%87%E4%BB%B6.jpg", result);
    }
    @Test
    public void testDecodeUrlPath() {
        // 准备参数:+ 是路径字符,不应该按 query parameter 语义解码为空格
        String path = "avatar/%E4%B8%AD%E6%96%87%20100%25+%E6%96%87%E4%BB%B6.jpg";
        // 调用
        String result = HttpUtils.decodeUrlPath(path);
        // 断言
        assertEquals("avatar/中文 100%+文件.jpg", result);
    }
    @Test
    public void testRemoveUrlPathQueryAndFragment() {
        assertEquals("avatar/test.jpg", HttpUtils.removeUrlPathQueryAndFragment("avatar/test.jpg?token=1#preview"));
        assertEquals("avatar/test.jpg", HttpUtils.removeUrlPathQueryAndFragment("avatar/test.jpg#preview?token=1"));
    }
    @Test
    public void testReplaceUrlQuery_replace() {
        // 准备参数
        String url = "https://www.iocoder.cn/path?a=1&b=2";