mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
Ignore patterns should be case insensitive on OS X and Windows
This commit is contained in:
parent
592b13d7db
commit
384c543ab9
@ -20,15 +20,22 @@ const (
|
|||||||
func Convert(pattern string, flags int) (*regexp.Regexp, error) {
|
func Convert(pattern string, flags int) (*regexp.Regexp, error) {
|
||||||
any := "."
|
any := "."
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
switch runtime.GOOS {
|
||||||
flags |= FNM_NOESCAPE
|
case "windows":
|
||||||
|
flags |= FNM_NOESCAPE | FNM_CASEFOLD
|
||||||
pattern = filepath.FromSlash(pattern)
|
pattern = filepath.FromSlash(pattern)
|
||||||
if flags&FNM_PATHNAME != 0 {
|
if flags&FNM_PATHNAME != 0 {
|
||||||
any = "[^\\\\]"
|
any = "[^\\\\]"
|
||||||
}
|
}
|
||||||
} else if flags&FNM_PATHNAME != 0 {
|
case "darwin":
|
||||||
any = "[^/]"
|
flags |= FNM_CASEFOLD
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
if flags&FNM_PATHNAME != 0 {
|
||||||
|
any = "[^/]"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags&FNM_NOESCAPE != 0 {
|
if flags&FNM_NOESCAPE != 0 {
|
||||||
pattern = strings.Replace(pattern, "\\", "\\\\", -1)
|
pattern = strings.Replace(pattern, "\\", "\\\\", -1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,12 +50,17 @@ var testcases = []testcase{
|
|||||||
{"**/foo.txt", "bar/baz/foo.txt", 0, true},
|
{"**/foo.txt", "bar/baz/foo.txt", 0, true},
|
||||||
{"**/foo.txt", "bar/baz/foo.txt", FNM_PATHNAME, true},
|
{"**/foo.txt", "bar/baz/foo.txt", FNM_PATHNAME, true},
|
||||||
|
|
||||||
{"foo.txt", "foo.TXT", 0, false},
|
|
||||||
{"foo.txt", "foo.TXT", FNM_CASEFOLD, true},
|
{"foo.txt", "foo.TXT", FNM_CASEFOLD, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatch(t *testing.T) {
|
func TestMatch(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
testcases = append(testcases, testcase{"foo.txt", "foo.TXT", 0, true})
|
||||||
|
case "darwin":
|
||||||
|
testcases = append(testcases, testcase{"foo.txt", "foo.TXT", 0, true})
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
testcases = append(testcases, testcase{"f\\[ab\\]o.txt", "f[ab]o.txt", 0, true})
|
testcases = append(testcases, testcase{"f\\[ab\\]o.txt", "f[ab]o.txt", 0, true})
|
||||||
testcases = append(testcases, testcase{"foo\\.txt", "foo.txt", 0, true})
|
testcases = append(testcases, testcase{"foo\\.txt", "foo.txt", 0, true})
|
||||||
testcases = append(testcases, testcase{"foo\\*.txt", "foo*.txt", 0, true})
|
testcases = append(testcases, testcase{"foo\\*.txt", "foo*.txt", 0, true})
|
||||||
|
@ -7,6 +7,7 @@ package ignore_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/ignore"
|
"github.com/syncthing/syncthing/ignore"
|
||||||
@ -106,3 +107,29 @@ func TestBadPatterns(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCaseSensitivity(t *testing.T) {
|
||||||
|
ign, _ := ignore.Parse(bytes.NewBufferString("test"), ".stignore")
|
||||||
|
|
||||||
|
match := []string{"test"}
|
||||||
|
dontMatch := []string{"foo"}
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin", "windows":
|
||||||
|
match = append(match, "TEST", "Test", "tESt")
|
||||||
|
default:
|
||||||
|
dontMatch = append(dontMatch, "TEST", "Test", "tESt")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range match {
|
||||||
|
if !ign.Match(tc) {
|
||||||
|
t.Errorf("Incorrect match for %q: should be matched", tc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range dontMatch {
|
||||||
|
if ign.Match(tc) {
|
||||||
|
t.Errorf("Incorrect match for %q: should not be matched", tc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user