Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix #652: Replace whitespace with dash in names of uploaded files #664

Merged
merged 1 commit into from
Jan 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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