From e4d6d3b085ec9bbc3193b83be2477589471bedaf Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Fri, 11 Mar 2022 09:35:48 +1100 Subject: [PATCH] Use case-insensitive matching in nameMatchesPath (#2378) * Use case-insensitive matching in nameMatchesPath Also ensures that only unique words are returned in getPathWords. --- pkg/match/path.go | 11 +++-------- pkg/match/path_test.go | 6 ++++++ ui/v2.5/src/components/Changelog/versions/v0140.md | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/match/path.go b/pkg/match/path.go index 6eb166e1e..e99ad82a5 100644 --- a/pkg/match/path.go +++ b/pkg/match/path.go @@ -11,6 +11,7 @@ import ( "github.com/stashapp/stash/pkg/image" "github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/scene" + "github.com/stashapp/stash/pkg/utils" ) const ( @@ -62,7 +63,7 @@ func getPathWords(path string) []string { // just use the first two characters // #2293 - need to convert to unicode runes for the substring, otherwise // the resulting string is corrupted. - ret = append(ret, string([]rune(w)[0:2])) + ret = utils.StrAppendUnique(ret, string([]rune(w)[0:2])) } } @@ -85,13 +86,7 @@ func nameMatchesPath(name, path string) int { // #2363 - optimisation: only use unicode character regexp if path contains // unicode characters re := nameToRegexp(name, !allASCII(path)) - found := re.FindAllStringIndex(path, -1) - - if found == nil { - return -1 - } - - return found[len(found)-1][0] + return regexpMatchesPath(re, path) } // nameToRegexp compiles a regexp pattern to match paths from the given name. diff --git a/pkg/match/path_test.go b/pkg/match/path_test.go index c162b8feb..f31aa2885 100644 --- a/pkg/match/path_test.go +++ b/pkg/match/path_test.go @@ -54,6 +54,12 @@ func Test_nameMatchesPath(t *testing.T) { "before_first last/after", 6, }, + { + "within string case insensitive", + name, + "before FIRST last/after", + 6, + }, { "not within string", name, diff --git a/ui/v2.5/src/components/Changelog/versions/v0140.md b/ui/v2.5/src/components/Changelog/versions/v0140.md index 8585d85b9..f77115be6 100644 --- a/ui/v2.5/src/components/Changelog/versions/v0140.md +++ b/ui/v2.5/src/components/Changelog/versions/v0140.md @@ -1,3 +1,6 @@ ### 🎨 Improvements * Allow customisation of UI theme color using `theme_color` property in `config.yml` ([#2365](https://github.com/stashapp/stash/pull/2365)) * Improved autotag performance. ([#2368](https://github.com/stashapp/stash/pull/2368)) + +### 🐛 Bug fixes +* Fix auto-tag not using case-insensitive matching. ([#2378](https://github.com/stashapp/stash/pull/2378)) \ No newline at end of file