diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 489be40f2..df6cc3dfa 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -27,17 +27,17 @@ 1.8.0 4.5.0 - 1.2.27 + 1.2.28 3.5.19 - 3.5.15 - 1.5.5 + 3.5.16 + 1.5.7 4.5.0 3.0.6 3.52.0 8.1.3.140 - 8.6.0 - 5.1.0 - 3.7.9 + 9.0.1.jre7 + 7.0.0-RC3-og + 3.8.3 2.3.5 @@ -58,36 +58,36 @@ 6.8.1 1.4.0 - 1.21.2 - 1.18.42 + 1.22.2 + 1.18.46 1.6.3 - 5.8.42 + 5.8.44 1.3.0 2.4 1.2.83 - 33.5.0-jre + 33.6.0-jre 2.14.5 - 3.12.0 + 3.13.0 3.20.0 - 2.27.7 + 2.28.2 2.9.3 2.7.0 3.0.6 0.10.2 - 4.2.9.Final + 4.2.12.Final 1.2.5 - 4.5.22 + 4.5.26 4.12.0 - 3.12.0 - 3.2.1 + 3.14.0 + 3.3.0 - 2.40.15 + 2.44.0 1.16.7 1.4.0 - 2.1.3 - 2.3.0 + 2.3.2 + 2.3.2 4.7.9-20251224.161447 - 4.40.607.ALL + 4.40.771.ALL 1.2.13 diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java index 04e29ed10..3488ddd4f 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java @@ -1,9 +1,7 @@ package cn.iocoder.yudao.framework.common.util.http; import cn.hutool.core.codec.Base64; -import cn.hutool.core.map.TableMap; import cn.hutool.core.net.url.UrlBuilder; -import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; @@ -70,9 +68,7 @@ public class HttpUtils { public static String replaceUrlQuery(String url, String key, String value) { UrlBuilder builder = UrlBuilder.of(url, Charset.defaultCharset()); // 先移除 - TableMap query = (TableMap) - ReflectUtil.getFieldValue(builder.getQuery(), "query"); - query.remove(key); + builder.getQuery().remove(key); // 后添加 builder.addQuery(key, value); return builder.build(); diff --git a/yudao-framework/yudao-common/src/test/java/cn/iocoder/yudao/framework/common/util/http/HttpUtilsTest.java b/yudao-framework/yudao-common/src/test/java/cn/iocoder/yudao/framework/common/util/http/HttpUtilsTest.java new file mode 100644 index 000000000..861598a56 --- /dev/null +++ b/yudao-framework/yudao-common/src/test/java/cn/iocoder/yudao/framework/common/util/http/HttpUtilsTest.java @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.framework.common.util.http; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class HttpUtilsTest { + + @Test + public void testReplaceUrlQuery() { + // 定义测试用例:{原始URL, Key, Value, 期望结果} + String[][] testCases = { + // 场景1: 替换已存在的参数 (注意参数顺序可能会变,因为 UrlQuery 内部是 List) + {"https://example.com/path?a=1&b=2", "a", "3", "https://example.com/path?b=2&a=3"}, + // 场景2: 添加不存在的参数 + {"https://example.com/path?a=1", "b", "2", "https://example.com/path?a=1&b=2"}, + // 场景3: URL 本身没有查询参数 + {"https://example.com/path", "a", "1", "https://example.com/path?a=1"}, + // 场景4: 值为空 (根据原逻辑,空值通常会被移除或不添加,这里假设是移除) + // 注意:你需要根据 HttpUtils 实际对 null/empty 的处理来调整 expected + {"https://example.com/path?a=1", "a", "", "https://example.com/path?a="}, + }; + + System.out.println("开始运行 HttpUtils.replaceUrlQuery 测试..."); + + for (int i = 0; i < testCases.length; i++) { + String[] currentCase = testCases[i]; // 必须先取出当前这一行的数组 + + String url = currentCase[0]; + String key = currentCase[1]; + String value = currentCase[2]; + String expected = currentCase[3]; + + // 调用你优化后的方法 + String actual = HttpUtils.replaceUrlQuery(url, key, value); + + // 核心验证:断言实际结果必须等于期望结果 + // 如果不相等,测试会直接报错,并打印出是哪一行错了 + try { + assertEquals(expected, actual, "测试用例 " + (i + 1) + " 失败: " + url); + System.out.println("✅ 用例 " + (i + 1) + " 通过: " + actual); + } catch (AssertionError e) { + System.err.println("❌ 用例 " + (i + 1) + " 失败!"); + System.err.println(" 输入: " + url + " | " + key + "=" + value); + System.err.println(" 期望: " + expected); + System.err.println(" 实际: " + actual); + throw e; // 抛出错误,让测试标记为失败 + } + } + } +} \ No newline at end of file