fix: sanitize tab chars and avoid double .md extension in manual download filename
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6752,12 +6752,15 @@ func ensureManualFileName(title string) string {
|
|||||||
// back to "untitled".
|
// back to "untitled".
|
||||||
func sanitizeManualDownloadFilename(title string) string {
|
func sanitizeManualDownloadFilename(title string) string {
|
||||||
safeName := strings.NewReplacer(
|
safeName := strings.NewReplacer(
|
||||||
"\n", "", "\r", "", "/", "-", "\\", "-", "\"", "'",
|
"\n", "", "\r", "", "\t", "", "/", "-", "\\", "-", "\"", "'",
|
||||||
).Replace(title)
|
).Replace(title)
|
||||||
if strings.TrimSpace(safeName) == "" {
|
if strings.TrimSpace(safeName) == "" {
|
||||||
safeName = "untitled"
|
safeName = "untitled"
|
||||||
}
|
}
|
||||||
return safeName + manualFileExtension
|
if !strings.HasSuffix(strings.ToLower(safeName), manualFileExtension) {
|
||||||
|
safeName += manualFileExtension
|
||||||
|
}
|
||||||
|
return safeName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *knowledgeService) triggerManualProcessing(ctx context.Context,
|
func (s *knowledgeService) triggerManualProcessing(ctx context.Context,
|
||||||
|
|||||||
@@ -72,6 +72,16 @@ func TestSanitizeManualDownloadFilename(t *testing.T) {
|
|||||||
title: "知识库文章",
|
title: "知识库文章",
|
||||||
want: "知识库文章.md",
|
want: "知识库文章.md",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "tab character stripped",
|
||||||
|
title: "file\tname",
|
||||||
|
want: "filename.md",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "title already ending in .md not double-extended",
|
||||||
|
title: "guide.md",
|
||||||
|
want: "guide.md",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user