文件名清理改为固定的 Windows 非法字符集,Linux CI 现在也会将 : 替换为 -。
清除了 DOCX 测试的空引用警告,以及 3 处 xUnit Assert.Single 分析器警告。
This commit is contained in:
1 parent
6e2eaad0fa
commit
8a72c1582c
4 files changed
+27
-14
No files matched your search
@@ -5,6 +5,11 @@ namespace Jiaowu.Api.Infrastructure.Files;
|
||||
/// </summary>
|
||||
public static class DownloadFileName
|
||||
{
|
||||
// Do not use Path.GetInvalidFileNameChars(): its result is platform-specific,
|
||||
// while downloaded names must remain usable on Windows regardless of where
|
||||
// the API is built or hosted.
|
||||
private static readonly char[] WindowsInvalidFileNameChars = ['<', '>', ':', '"', '/', '\\', '|', '?', '*'];
|
||||
|
||||
public static string Export(string title, string extension, params string?[] parts) =>
|
||||
Build(title, extension, includeTimestamp: true, parts);
|
||||
|
||||
@@ -33,9 +38,8 @@ public static class DownloadFileName
|
||||
private static string Clean(string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) return string.Empty;
|
||||
var invalid = Path.GetInvalidFileNameChars();
|
||||
var cleaned = new string(value.Trim().Select(character =>
|
||||
invalid.Contains(character) ? '-' : character).ToArray());
|
||||
WindowsInvalidFileNameChars.Contains(character) || char.IsControl(character) ? '-' : character).ToArray());
|
||||
return cleaned.Trim('.', ' ');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user