Fix issue with backslashes when using pattern function

This commit is contained in:
TwinProduction
2021-01-04 18:01:39 -05:00
parent f1c0bbe73c
commit c27cb7af08
3 changed files with 45 additions and 11 deletions

View File

@ -1,12 +1,19 @@
package pattern
import "path/filepath"
import (
"path/filepath"
"strings"
)
// Match checks whether a string matches a pattern
func Match(pattern, s string) bool {
if pattern == "*" {
return true
}
// Backslashes break filepath.Match, so we'll remove all of them.
// This has a pretty significant impact on performance when there
// are backslashes, but at least it doesn't break filepath.Match.
s = strings.ReplaceAll(s, "\\", "")
matched, _ := filepath.Match(pattern, s)
return matched
}