Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Apr 24, 2024
2 parents 4902b72 + 2b82c36 commit 7675d2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions tools/filesystem/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func normalizeName(fr FileReader, name string) string {
// try to detect the extension from the file content
cleanExt, _ = detectExtension(fr)
}
if extLength := len(cleanExt); extLength > 20 {
// keep only the last 20 characters (it is multibyte safe after the regex replace)
cleanExt = "." + cleanExt[extLength-20:]
}

// name
// ---
Expand Down
16 changes: 9 additions & 7 deletions tools/filesystem/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"

"github.com/labstack/echo/v5"
Expand Down Expand Up @@ -182,13 +183,14 @@ func TestFileNameNormalizations(t *testing.T) {
name string
pattern string
}{
{"", `^\w{10}_\w{10}.txt$`},
{".png", `^\w{10}_\w{10}.png$`},
{".tar.gz", `^\w{10}_\w{10}.tar.gz$`},
{"a.tar.gz", `^a\w{10}_\w{10}.tar.gz$`},
{"a.b.c.d.tar.gz", `^a_b_c_d_\w{10}.tar.gz$`},
{"abcd", `^abcd_\w{10}.txt$`},
{"a b! c d . 456", `^a_b_c_d_\w{10}.456$`}, // normalize spaces
{"", `^\w{10}_\w{10}\.txt$`},
{".png", `^\w{10}_\w{10}\.png$`},
{".tar.gz", `^\w{10}_\w{10}\.tar\.gz$`},
{"a.tar.gz", `^a\w{10}_\w{10}\.tar\.gz$`},
{"a.b.c.d.tar.gz", `^a_b_c_d_\w{10}\.tar\.gz$`},
{"abcd", `^abcd_\w{10}\.txt$`},
{"a b! c d . 456", `^a_b_c_d_\w{10}\.456$`}, // normalize spaces
{strings.Repeat("a", 101) + "." + strings.Repeat("b", 21), `^a{100}_\w{10}\.b{20}$`}, // name and extension length trim
}

for i, s := range scenarios {
Expand Down

0 comments on commit 7675d2e

Please sign in to comment.