Ver Fonte

为WebUtils.encodeUrlFileName方法添加测试用例

jerrykcode há 3 anos atrás
pai
commit
f2d5f4a86c
1 ficheiros alterados com 24 adições e 0 exclusões
  1. 24 0
      server/src/test/java/cn/keking/utils/WebUtilsTests.java

+ 24 - 0
server/src/test/java/cn/keking/utils/WebUtilsTests.java

@@ -0,0 +1,24 @@
+package cn.keking.utils;
+
+import org.junit.jupiter.api.Test;
+
+public class WebUtilsTests {
+
+    @Test
+    void encodeUrlFileNameTest() {
+        // 测试对URL中的文件名部分进行UTF-8编码
+        String in = "https://file.keking.cn/demo/hello#0.txt";
+        String out = "https://file.keking.cn/demo/hello%230.txt";
+        assert WebUtils.encodeUrlFileName(in).equals(out);
+    }
+
+    @Test
+    void encodeUrlFileNameTestWithParams() {
+        // 测试对URL中的文件名部分进行UTF-8编码
+        // URL带参数
+        // 文件名"#hello&world"中的"&"应该被编码成为"%26",而?后的参数列表中的"&"不会被编码
+        String in = "https://file.keking.cn/demo/#hello&world.txt?param0=0&param1=1";
+        String out = "https://file.keking.cn/demo/%23hello%26world.txt?param0=0&param1=1";
+        assert WebUtils.encodeUrlFileName(in).equals(out);
+    }
+}