mirror of
https://github.com/stashapp/stash.git
synced 2026-04-19 21:41:42 +02:00
Use case-insensitive matching in nameMatchesPath (#2378)
Also ensures that only unique words are returned in getPathWords.
This commit is contained in:
parent
740426515e
commit
4d800a14f4
2 changed files with 9 additions and 8 deletions
|
|
@ -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 (
|
||||
|
|
@ -67,7 +68,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]))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,13 +91,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.
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue