diff --git a/zglob.go b/zglob.go index cf7ccc4..4e79583 100644 --- a/zglob.go +++ b/zglob.go @@ -110,6 +110,21 @@ func New(pattern string) (*zenv, error) { } else { filemask += "[^/]*" } + } else if cc[i] == '[' { // range + staticDir = false + pattern := "" + for j := i + 1; j < len(cc); j++ { + if cc[j] == ']' { + i = j + break + } else { + pattern += string(cc[j]) + } + } + if pattern != "" { + filemask += "[" + pattern + "]" + continue + } } else { if cc[i] == '{' { staticDir = false diff --git a/zglob_test.go b/zglob_test.go index deb7a4b..3b986e4 100644 --- a/zglob_test.go +++ b/zglob_test.go @@ -27,6 +27,10 @@ var testGlobs = []testZGlob{ {`fo*`, []string{`foo`}, nil}, {`foo`, []string{`foo`}, nil}, {`foo/*`, []string{`foo/bar`, `foo/baz`}, nil}, + {`foo/b[a]*`, []string{`foo/bar`, `foo/baz`}, nil}, + {`foo/b[a][r]*`, []string{`foo/bar`}, nil}, + {`foo/b[a-z]*`, []string{`foo/bar`, `foo/baz`}, nil}, + {`foo/b[c-z]*`, []string{}, nil}, {`foo/**`, []string{`foo/bar`, `foo/baz`}, nil}, {`f*o/**`, []string{`foo/bar`, `foo/baz`}, nil}, {`*oo/**`, []string{`foo/bar`, `foo/baz`, `hoo/bar`}, nil},