added test for file name normalization with leading dot
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
## v0.35 (WIP)
|
||||
## v0.35.0
|
||||
|
||||
- Added `nullString()`, `nullInt()`, `nullFloat()`, `nullBool`, `nullArray()`, `nullObject()` JSVM helpers for scanning nullable columns ([#7396](https://github.com/pocketbase/pocketbase/issues/7396)).
|
||||
(@todo update the landing docs)
|
||||
|
||||
- Store the correct `image/png` as attrs content type when generating a thumb fallback _(e.g. for `webp`)_.
|
||||
|
||||
- Trimmed the normalized file extension from leftover `.` characters after cleanup.
|
||||
- Trimmed the uploaded file name and extension from leftover `.` characters after normalization.
|
||||
_This was done to prevent issues with external files sync programs that may have special handling for "invisible" files._
|
||||
|
||||
- Updated Go deps.
|
||||
|
||||
|
||||
@@ -207,6 +207,9 @@ func normalizeName(fr FileReader, name string) string {
|
||||
}
|
||||
|
||||
// name
|
||||
//
|
||||
// note: leading dot is trimmed to prevent various subtle issues with files
|
||||
// sync programs as they sometimes have special handling for "invisible" files
|
||||
// ---
|
||||
cleanName := inflector.Snakecase(strings.Trim(strings.TrimSuffix(name, originalExt), "."))
|
||||
if length := len(cleanName); length < 3 {
|
||||
|
||||
@@ -215,6 +215,7 @@ func TestFileNameNormalizations(t *testing.T) {
|
||||
{"a.b.c.?.?.?.2", `^a_b_c_\w{10}\.2$`},
|
||||
{"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
|
||||
}
|
||||
@@ -225,7 +226,8 @@ func TestFileNameNormalizations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if match, err := regexp.Match(s.pattern, []byte(f.Name)); !match {
|
||||
match, err := regexp.Match(s.pattern, []byte(f.Name))
|
||||
if !match {
|
||||
t.Fatalf("Expected Name to match %v, got %q (%v)", s.pattern, f.Name, err)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user