mirror of
https://github.com/knadh/listmonk.git
synced 2025-01-09 16:00:22 +08:00
Replace whitespace with dash in names of uploaded files
This commit is contained in:
parent
a2458cf668
commit
be1d048e7b
1 changed files with 4 additions and 2 deletions
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tagRegexpSpaces = regexp.MustCompile(`[\s]+`)
|
regexpSpaces = regexp.MustCompile(`[\s]+`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// inArray checks if a string is present in a list of strings.
|
// inArray checks if a string is present in a list of strings.
|
||||||
|
@ -32,6 +32,8 @@ func makeFilename(fName string) string {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name, _ = generateRandomString(10)
|
name, _ = generateRandomString(10)
|
||||||
}
|
}
|
||||||
|
// replace whitespace with "-"
|
||||||
|
name = regexpSpaces.ReplaceAllString(name, "-")
|
||||||
return filepath.Base(name)
|
return filepath.Base(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +57,7 @@ func normalizeTags(tags []string) []string {
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, t := range tags {
|
for _, t := range tags {
|
||||||
rep := tagRegexpSpaces.ReplaceAll(bytes.TrimSpace([]byte(t)), dash)
|
rep := regexpSpaces.ReplaceAll(bytes.TrimSpace([]byte(t)), dash)
|
||||||
|
|
||||||
if len(rep) > 0 {
|
if len(rep) > 0 {
|
||||||
out = append(out, string(rep))
|
out = append(out, string(rep))
|
||||||
|
|
Loading…
Reference in a new issue