Skip to content

Commit b7a5fe6

Browse files
committed
add: sanitize file name #117
1 parent 063d41c commit b7a5fe6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cmd/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func downloadDocument(ctx context.Context, client *core.Client, url string, opts
104104
// Write to markdown file
105105
mdName := fmt.Sprintf("%s.md", docToken)
106106
if dlConfig.Output.TitleAsFilename {
107-
mdName = fmt.Sprintf("%s.md", title)
107+
mdName = fmt.Sprintf("%s.md", utils.SanitizeFileName(title))
108108
}
109109
outputPath := filepath.Join(opts.outputDir, mdName)
110110
if err = os.WriteFile(outputPath, []byte(result), 0o644); err != nil {

utils/common.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ func PrettyPrint(i interface{}) string {
2929
s, _ := json.MarshalIndent(i, "", " ")
3030
return string(s)
3131
}
32+
33+
func SanitizeFileName(title string) string {
34+
invalidChars := []string{"/", "\\", ":", "*", "?", "\"", "<", ">", "|"}
35+
for _, char := range invalidChars {
36+
title = strings.ReplaceAll(title, char, "_")
37+
}
38+
return title
39+
}

0 commit comments

Comments
 (0)