mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
Also handle ()| in glob patterns (fixes #1365)
This commit is contained in:
parent
8b66472949
commit
1e4b2133f6
@ -54,17 +54,22 @@ func Convert(pattern string, flags int) (*regexp.Regexp, error) {
|
||||
pattern = strings.Replace(pattern, "\\?", "[:escapedques:]", -1)
|
||||
pattern = strings.Replace(pattern, "\\.", "[:escapeddot:]", -1)
|
||||
}
|
||||
pattern = strings.Replace(pattern, ".", "\\.", -1)
|
||||
pattern = strings.Replace(pattern, "+", "\\+", -1)
|
||||
pattern = strings.Replace(pattern, "$", "\\$", -1)
|
||||
pattern = strings.Replace(pattern, "^", "\\^", -1)
|
||||
|
||||
// Characters that are special in regexps but not in glob, must be
|
||||
// escaped.
|
||||
for _, char := range []string{".", "+", "$", "^", "(", ")", "|"} {
|
||||
pattern = strings.Replace(pattern, char, "\\"+char, -1)
|
||||
}
|
||||
|
||||
pattern = strings.Replace(pattern, "**", "[:doublestar:]", -1)
|
||||
pattern = strings.Replace(pattern, "*", any+"*", -1)
|
||||
pattern = strings.Replace(pattern, "[:doublestar:]", ".*", -1)
|
||||
pattern = strings.Replace(pattern, "?", any, -1)
|
||||
|
||||
pattern = strings.Replace(pattern, "[:escapedstar:]", "\\*", -1)
|
||||
pattern = strings.Replace(pattern, "[:escapedques:]", "\\?", -1)
|
||||
pattern = strings.Replace(pattern, "[:escapeddot:]", "\\.", -1)
|
||||
|
||||
pattern = "^" + pattern + "$"
|
||||
if flags&FNM_CASEFOLD != 0 {
|
||||
pattern = "(?i)" + pattern
|
||||
|
@ -68,6 +68,10 @@ var testcases = []testcase{
|
||||
{"hey^hello", "hey^hello", 0, true},
|
||||
{"hey{hello", "hey{hello", 0, true},
|
||||
{"hey}hello", "hey}hello", 0, true},
|
||||
{"hey(hello", "hey(hello", 0, true},
|
||||
{"hey)hello", "hey)hello", 0, true},
|
||||
{"hey|hello", "hey|hello", 0, true},
|
||||
{"hey|hello", "hey|other", 0, false},
|
||||
}
|
||||
|
||||
func TestMatch(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user