From 895746267255af658e33b6e6a8226b45a50e87f2 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 20 Sep 2023 17:13:25 +0200 Subject: [PATCH] Library: Allow "#" at the beginning of path names #3695 Signed-off-by: Michael Mayer --- pkg/clean/path.go | 4 ++-- pkg/clean/path_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/clean/path.go b/pkg/clean/path.go index cca0e5740..bf1f44720 100644 --- a/pkg/clean/path.go +++ b/pkg/clean/path.go @@ -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 "" diff --git a/pkg/clean/path_test.go b/pkg/clean/path_test.go index cd1b699e0..ddaf9dca1 100644 --- a/pkg/clean/path_test.go +++ b/pkg/clean/path_test.go @@ -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://:/}")) }) + 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/"))