Library: Allow "#" at the beginning of path names #3695
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
4d1003846c
commit
8957462672
2 changed files with 14 additions and 2 deletions
|
@ -22,7 +22,7 @@ func Path(s string) string {
|
|||
}
|
||||
|
||||
switch r {
|
||||
case '~', '\\', '|', '"', '?', '*', '<', '>', '{', '}':
|
||||
case '\\', '|', '"', '?', '*', '%', '<', '>', '{', '}':
|
||||
return -1
|
||||
default:
|
||||
return r
|
||||
|
@ -38,7 +38,7 @@ func UserPath(dir string) string {
|
|||
return dir
|
||||
}
|
||||
|
||||
dir = strings.Trim(path.Clean(Path(strings.ReplaceAll(dir, "\\", "/"))), "./ \\*%#~?|<>")
|
||||
dir = strings.Trim(path.Clean(Path(strings.ReplaceAll(dir, "\\", "/"))), " ./\\|?*%<>")
|
||||
|
||||
if strings.Contains(dir, "/.") || strings.Contains(dir, "..") || strings.Contains(dir, "//") {
|
||||
return ""
|
||||
|
|
|
@ -40,6 +40,12 @@ func TestPath(t *testing.T) {
|
|||
t.Run("Special Chars", func(t *testing.T) {
|
||||
assert.Equal(t, "filename.", Path("filename.?**"))
|
||||
})
|
||||
t.Run("IncludesHash", func(t *testing.T) {
|
||||
assert.Equal(t, "1970-05 (Tray #005) to 3-78 Person-Abbrev Place", Path("1970-05 (Tray #005) to 3-78 Person-Abbrev Place"))
|
||||
})
|
||||
t.Run("StartsWithHash", func(t *testing.T) {
|
||||
assert.Equal(t, "#2020", Path("#2020"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestUserPath(t *testing.T) {
|
||||
|
@ -70,6 +76,12 @@ func TestUserPath(t *testing.T) {
|
|||
t.Run("Replace", func(t *testing.T) {
|
||||
assert.Equal(t, "", UserPath("${https://<host>:<port>/<path>}"))
|
||||
})
|
||||
t.Run("IncludesHash", func(t *testing.T) {
|
||||
assert.Equal(t, "1970-05 (Tray #005) to 3-78 Person-Abbrev Place", UserPath("1970-05 (Tray #005) to 3-78 Person-Abbrev Place"))
|
||||
})
|
||||
t.Run("StartsWithHash", func(t *testing.T) {
|
||||
assert.Equal(t, "#2020", UserPath("#2020"))
|
||||
})
|
||||
t.Run("Unclean", func(t *testing.T) {
|
||||
assert.Equal(t, "foo/bar/baz", UserPath("/foo/bar/baz/"))
|
||||
assert.Equal(t, "dirty/path", UserPath("/dirty/path/"))
|
||||
|
|
Loading…
Reference in a new issue