From 1e20c6dbac3e865d289d5edb5e18368fbc897c5c Mon Sep 17 00:00:00 2001 From: Bob Matcuk Date: Fri, 11 Oct 2024 09:51:06 -0400 Subject: [PATCH] fixes #95 FilepathGlob("") should return nil --- doublestar_test.go | 1 + utils.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/doublestar_test.go b/doublestar_test.go index 26ff894..bf6414e 100644 --- a/doublestar_test.go +++ b/doublestar_test.go @@ -28,6 +28,7 @@ type MatchTest struct { var onWindows = runtime.GOOS == "windows" var matchTests = []MatchTest{ + {"", "", true, false, nil, true, false, true, true, 0, 0}, {"*", "", true, true, nil, false, false, true, false, 0, 0}, {"*", "/", false, false, nil, false, false, true, false, 0, 0}, {"/*", "/", true, true, nil, false, false, true, false, 0, 0}, diff --git a/utils.go b/utils.go index 0ab1dc9..6b8df9a 100644 --- a/utils.go +++ b/utils.go @@ -84,6 +84,16 @@ func SplitPattern(p string) (base, pattern string) { // filepath.ErrBadPattern. // func FilepathGlob(pattern string, opts ...GlobOption) (matches []string, err error) { + if pattern == "" { + // special case to match filepath.Glob behavior + g := newGlob(opts...) + if g.failOnIOErrors { + // match doublestar.Glob behavior here + return nil, os.ErrInvalid + } + return nil, nil + } + pattern = filepath.Clean(pattern) pattern = filepath.ToSlash(pattern) base, f := SplitPattern(pattern)