diff --git a/internal/fnmatch/fnmatch.go b/internal/fnmatch/fnmatch.go index df19b29d..74a12754 100644 --- a/internal/fnmatch/fnmatch.go +++ b/internal/fnmatch/fnmatch.go @@ -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, "**", "[:doublestar:]", -1) pattern = strings.Replace(pattern, "*", any+"*", -1) pattern = strings.Replace(pattern, "[:doublestar:]", ".*", -1) diff --git a/internal/fnmatch/fnmatch_test.go b/internal/fnmatch/fnmatch_test.go index 1a7fead7..f12c9859 100644 --- a/internal/fnmatch/fnmatch_test.go +++ b/internal/fnmatch/fnmatch_test.go @@ -62,6 +62,12 @@ var testcases = []testcase{ {"**/foo.txt", "bar/baz/foo.txt", FNM_PATHNAME, 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) {