mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-05-18 22:00:21 -04:00
cap the file name before normalization
This commit is contained in:
@@ -193,6 +193,13 @@ var extInvalidCharsRegex = regexp.MustCompile(`[^\w\.\*\-\+\=\#]+`)
|
||||
const randomAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
|
||||
func normalizeName(fr FileReader, name string) string {
|
||||
// cut the name even if it is not multibyte safe to avoid operating on too large strings
|
||||
// ---
|
||||
originalLength := len(name)
|
||||
if originalLength > 300 {
|
||||
name = name[originalLength-300:]
|
||||
}
|
||||
|
||||
// extension
|
||||
// ---
|
||||
originalExt := extractExtension(name)
|
||||
|
||||
@@ -216,8 +216,9 @@ func TestFileNameNormalizations(t *testing.T) {
|
||||
{"a.b.c.d.tar.gz", `^a_b_c_d_\w{10}\.tar\.gz$`},
|
||||
{"abcd", `^abcd_\w{10}\.txt$`},
|
||||
{".abcd.123.", `^abcd_\w{10}\.123$`},
|
||||
{"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
|
||||
{"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 cut
|
||||
{"abc" + strings.Repeat("d", 290) + "." + strings.Repeat("b", 9), `^d{100}_\w{10}\.b{9}$`}, // initial total lenght cut
|
||||
}
|
||||
|
||||
for i, s := range scenarios {
|
||||
|
||||
Reference in New Issue
Block a user