mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Escape all regexp control characters (#1753)
* Escape all regexp control characters * Add #1752 unit tests Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
parent
cceaff780b
commit
1e8a8efe3e
5 changed files with 31 additions and 15 deletions
|
|
@ -23,6 +23,10 @@ func TestPerformerScenes(t *testing.T) {
|
||||||
"performer + name",
|
"performer + name",
|
||||||
`(?i)(?:^|_|[^\w\d])performer[.\-_ ]*\+[.\-_ ]*name(?:$|_|[^\w\d])`,
|
`(?i)(?:^|_|[^\w\d])performer[.\-_ ]*\+[.\-_ ]*name(?:$|_|[^\w\d])`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`performer + name\`,
|
||||||
|
`(?i)(?:^|_|[^\w\d])performer[.\-_ ]*\+[.\-_ ]*name\\(?:$|_|[^\w\d])`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range performerNames {
|
for _, p := range performerNames {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ var testStudioCases = []testStudioCase{
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`studio + name\`,
|
||||||
|
`(?i)(?:^|_|[^\w\d])studio[.\-_ ]*\+[.\-_ ]*name\\(?:$|_|[^\w\d])`,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"studio name",
|
"studio name",
|
||||||
`(?i)(?:^|_|[^\w\d])studio[.\-_ ]*name(?:$|_|[^\w\d])`,
|
`(?i)(?:^|_|[^\w\d])studio[.\-_ ]*name(?:$|_|[^\w\d])`,
|
||||||
|
|
@ -40,6 +46,12 @@ var testStudioCases = []testStudioCase{
|
||||||
"alias + name",
|
"alias + name",
|
||||||
`(?i)(?:^|_|[^\w\d])alias[.\-_ ]*\+[.\-_ ]*name(?:$|_|[^\w\d])`,
|
`(?i)(?:^|_|[^\w\d])alias[.\-_ ]*\+[.\-_ ]*name(?:$|_|[^\w\d])`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`studio + name\`,
|
||||||
|
`(?i)(?:^|_|[^\w\d])studio[.\-_ ]*\+[.\-_ ]*name\\(?:$|_|[^\w\d])`,
|
||||||
|
`alias + name\`,
|
||||||
|
`(?i)(?:^|_|[^\w\d])alias[.\-_ ]*\+[.\-_ ]*name\\(?:$|_|[^\w\d])`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStudioScenes(t *testing.T) {
|
func TestStudioScenes(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ var testTagCases = []testTagCase{
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`tag + name\`,
|
||||||
|
`(?i)(?:^|_|[^\w\d])tag[.\-_ ]*\+[.\-_ ]*name\\(?:$|_|[^\w\d])`,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"tag name",
|
"tag name",
|
||||||
`(?i)(?:^|_|[^\w\d])tag[.\-_ ]*name(?:$|_|[^\w\d])`,
|
`(?i)(?:^|_|[^\w\d])tag[.\-_ ]*name(?:$|_|[^\w\d])`,
|
||||||
|
|
@ -40,6 +46,12 @@ var testTagCases = []testTagCase{
|
||||||
"alias + name",
|
"alias + name",
|
||||||
`(?i)(?:^|_|[^\w\d])alias[.\-_ ]*\+[.\-_ ]*name(?:$|_|[^\w\d])`,
|
`(?i)(?:^|_|[^\w\d])alias[.\-_ ]*\+[.\-_ ]*name(?:$|_|[^\w\d])`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`tag + name\`,
|
||||||
|
`(?i)(?:^|_|[^\w\d])tag[.\-_ ]*\+[.\-_ ]*name\\(?:$|_|[^\w\d])`,
|
||||||
|
`alias + name\`,
|
||||||
|
`(?i)(?:^|_|[^\w\d])alias[.\-_ ]*\+[.\-_ ]*name\\(?:$|_|[^\w\d])`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTagScenes(t *testing.T) {
|
func TestTagScenes(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -25,22 +25,9 @@ import (
|
||||||
|
|
||||||
const separatorChars = `.\-_ `
|
const separatorChars = `.\-_ `
|
||||||
|
|
||||||
// fixes #1292
|
|
||||||
func escapePathRegex(name string) string {
|
|
||||||
ret := name
|
|
||||||
|
|
||||||
chars := `+*?()|[]{}^$`
|
|
||||||
for _, c := range chars {
|
|
||||||
cStr := string(c)
|
|
||||||
ret = strings.ReplaceAll(ret, cStr, `\`+cStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPathQueryRegex(name string) string {
|
func getPathQueryRegex(name string) string {
|
||||||
// escape specific regex characters
|
// escape specific regex characters
|
||||||
name = escapePathRegex(name)
|
name = regexp.QuoteMeta(name)
|
||||||
|
|
||||||
// handle path separators
|
// handle path separators
|
||||||
const separator = `[` + separatorChars + `]`
|
const separator = `[` + separatorChars + `]`
|
||||||
|
|
@ -52,7 +39,7 @@ func getPathQueryRegex(name string) string {
|
||||||
|
|
||||||
func nameMatchesPath(name, path string) bool {
|
func nameMatchesPath(name, path string) bool {
|
||||||
// escape specific regex characters
|
// escape specific regex characters
|
||||||
name = escapePathRegex(name)
|
name = regexp.QuoteMeta(name)
|
||||||
|
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
path = strings.ToLower(path)
|
path = strings.ToLower(path)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
* Added sv-SE language option. ([#1691](https://github.com/stashapp/stash/pull/1691))
|
* Added sv-SE language option. ([#1691](https://github.com/stashapp/stash/pull/1691))
|
||||||
|
|
||||||
### 🐛 Bug fixes
|
### 🐛 Bug fixes
|
||||||
|
* Fix panic in autotagger when backslash character present in tag/performer/studio name. ([#1753](https://github.com/stashapp/stash/pull/1753))
|
||||||
* Fix Scene Player CLS issue ([#1739](https://github.com/stashapp/stash/pull/1739))
|
* Fix Scene Player CLS issue ([#1739](https://github.com/stashapp/stash/pull/1739))
|
||||||
* Fix Scene Edit Panel form layout for mobile and desktop. ([#1737](https://github.com/stashapp/stash/pull/1737))
|
* Fix Scene Edit Panel form layout for mobile and desktop. ([#1737](https://github.com/stashapp/stash/pull/1737))
|
||||||
* Fix Gallery create plugin hook not being invoked when creating Gallery from folder. ([#1731](https://github.com/stashapp/stash/pull/1731))
|
* Fix Gallery create plugin hook not being invoked when creating Gallery from folder. ([#1731](https://github.com/stashapp/stash/pull/1731))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue