feat(policy): opt-in native file name characters per policy (#3065)
Uploads/rename rejected :*?"<>| unconditionally since the strict set protects clients mounting on Windows. Add a per-policy allow_native_name toggle: when enabled, Windows-only illegal characters are accepted in file names; path separators and dot-names stay illegal regardless. Folder creation keeps the strict set since its governing policy is ambiguous. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>pull/3582/head
parent
4b5433179e
commit
d15a452e6f
@ -0,0 +1,27 @@
|
||||
package dbfs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidateFileNameNativeChars(t *testing.T) {
|
||||
native := &ent.StoragePolicy{Settings: &types.PolicySetting{AllowNativeName: true}}
|
||||
|
||||
// Windows-illegal characters accepted only under allow_native_name.
|
||||
for _, name := range []string{"a:b.txt", "a<b>.txt", "a|b?.txt", `say "hi".txt`} {
|
||||
require.Error(t, validateFileName(name, nil))
|
||||
require.Error(t, validateFileName(name, &ent.StoragePolicy{Settings: &types.PolicySetting{}}))
|
||||
require.NoError(t, validateFileName(name, native))
|
||||
}
|
||||
|
||||
// Separators and dot-names stay illegal regardless.
|
||||
for _, name := range []string{"a/b", `a\b`, ".", "..", "", string(make([]byte, 300))} {
|
||||
require.Error(t, validateFileName(name, native))
|
||||
}
|
||||
|
||||
require.NoError(t, validateFileName("normal file.txt", nil))
|
||||
}
|
||||
Loading…
Reference in new issue