From 93dd97afb79157cf81027cc4a628f8cfff197167 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 7 Jun 2026 14:19:13 +0800 Subject: [PATCH] fix(infra): 修复文件 URL 特殊字符编码问题 --- yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtilsTest.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+), 0 deletions(-) create mode 100644 yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtilsTest.java diff --git a/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtilsTest.java b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtilsTest.java new file mode 100644 index 0000000..d13884b --- /dev/null +++ b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtilsTest.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.infra.framework.file.core.utils; + +import org.junit.jupiter.api.Test; +import org.springframework.mock.web.MockHttpServletResponse; + +import java.nio.charset.StandardCharsets; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * {@link FileTypeUtils} 的单元测试 + */ +public class FileTypeUtilsTest { + + @Test + public void testWriteAttachment_contentDispositionEncodeFilename() throws Exception { + // 准备参数 + MockHttpServletResponse response = new MockHttpServletResponse(); + byte[] content = "test".getBytes(StandardCharsets.UTF_8); + + // 调用 + FileTypeUtils.writeAttachment(response, "中文 100%+文件.txt", content); + + // 断言 + assertEquals("attachment;filename=\"__ 100%+__.txt\";" + + "filename*=UTF-8''%E4%B8%AD%E6%96%87%20100%25+%E6%96%87%E4%BB%B6.txt", + response.getHeader("Content-Disposition")); + assertArrayEquals(content, response.getContentAsByteArray()); + } + +} -- libgit2 0.21.4