mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Correctly handle ^ and $ in ignore patterns (fixes #1365)
This commit is contained in:
parent
efd6a29909
commit
7921082ece
@ -56,6 +56,8 @@ func Convert(pattern string, flags int) (*regexp.Regexp, error) {
|
|||||||
}
|
}
|
||||||
pattern = strings.Replace(pattern, ".", "\\.", -1)
|
pattern = strings.Replace(pattern, ".", "\\.", -1)
|
||||||
pattern = strings.Replace(pattern, "+", "\\+", -1)
|
pattern = strings.Replace(pattern, "+", "\\+", -1)
|
||||||
|
pattern = strings.Replace(pattern, "$", "\\$", -1)
|
||||||
|
pattern = strings.Replace(pattern, "^", "\\^", -1)
|
||||||
pattern = strings.Replace(pattern, "**", "[:doublestar:]", -1)
|
pattern = strings.Replace(pattern, "**", "[:doublestar:]", -1)
|
||||||
pattern = strings.Replace(pattern, "*", any+"*", -1)
|
pattern = strings.Replace(pattern, "*", any+"*", -1)
|
||||||
pattern = strings.Replace(pattern, "[:doublestar:]", ".*", -1)
|
pattern = strings.Replace(pattern, "[:doublestar:]", ".*", -1)
|
||||||
|
@ -62,6 +62,12 @@ var testcases = []testcase{
|
|||||||
{"**/foo.txt", "bar/baz/foo.txt", FNM_PATHNAME, true},
|
{"**/foo.txt", "bar/baz/foo.txt", FNM_PATHNAME, true},
|
||||||
|
|
||||||
{"foo.txt", "foo.TXT", FNM_CASEFOLD, true},
|
{"foo.txt", "foo.TXT", FNM_CASEFOLD, true},
|
||||||
|
|
||||||
|
// These characters are literals in glob, but not in regexp.
|
||||||
|
{"hey$hello", "hey$hello", 0, true},
|
||||||
|
{"hey^hello", "hey^hello", 0, true},
|
||||||
|
{"hey{hello", "hey{hello", 0, true},
|
||||||
|
{"hey}hello", "hey}hello", 0, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatch(t *testing.T) {
|
func TestMatch(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user