Skip to content

Commit

Permalink
Merge pull request #664 from nikochiko/spaces-in-filenames
Browse files Browse the repository at this point in the history
Fix #652: Replace whitespace with dash in names of uploaded files
  • Loading branch information
knadh authored Jan 15, 2022
2 parents a2458cf + be1d048 commit 740373d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var (
tagRegexpSpaces = regexp.MustCompile(`[\s]+`)
regexpSpaces = regexp.MustCompile(`[\s]+`)
)

// inArray checks if a string is present in a list of strings.
Expand All @@ -32,6 +32,8 @@ func makeFilename(fName string) string {
if name == "" {
name, _ = generateRandomString(10)
}
// replace whitespace with "-"
name = regexpSpaces.ReplaceAllString(name, "-")
return filepath.Base(name)
}

Expand All @@ -55,7 +57,7 @@ func normalizeTags(tags []string) []string {
)

for _, t := range tags {
rep := tagRegexpSpaces.ReplaceAll(bytes.TrimSpace([]byte(t)), dash)
rep := regexpSpaces.ReplaceAll(bytes.TrimSpace([]byte(t)), dash)

if len(rep) > 0 {
out = append(out, string(rep))
Expand Down

0 comments on commit 740373d

Please sign in to comment.