aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-10-22 12:11:29 -0400
committerRuss Cox <rsc@golang.org>2020-10-23 14:59:03 +0000
commitb5ddc42b465dd5b9532ee336d98343d81a6d35b2 (patch)
treed3ea8f2fe5c41f4befebaeda5600832839b0bbbb /src/testing
parent4a2cc73f8789e3df43c1c96944c90f55757a23b0 (diff)
downloadgo-b5ddc42b465dd5b9532ee336d98343d81a6d35b2.tar.gz
go-b5ddc42b465dd5b9532ee336d98343d81a6d35b2.zip
io/fs, path, path/filepath, testing/fstest: validate patterns in Match, Glob
According to #28614, proposal review agreed in December 2018 that Match should return an error for failed matches where the unmatched part of the pattern has a syntax error. (The failed match has to date caused the scan of the pattern to stop early.) This change implements that behavior: the match loop continues scanning to the end of the pattern, even after a confirmed mismatch, to check whether the pattern is even well-formed. The change applies to both path.Match and filepath.Match. Then filepath.Glob and fs.Glob make a single validity-checking call to Match before beginning their usual processing. Also update fstest.TestFS to check for correct validation in custom Glob implementations. Fixes #28614. Change-Id: Ic1d35a4bb9c3565184ae83dbefc425c5c96318e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/264397 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/fstest/testfs.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go
index 21cd00e5b6..4912a271b2 100644
--- a/src/testing/fstest/testfs.go
+++ b/src/testing/fstest/testfs.go
@@ -282,6 +282,12 @@ func (t *fsTester) checkGlob(dir string, list []fs.DirEntry) {
glob = strings.Join(elem, "/") + "/"
}
+ // Test that malformed patterns are detected.
+ // The error is likely path.ErrBadPattern but need not be.
+ if _, err := t.fsys.(fs.GlobFS).Glob(glob + "nonexist/[]"); err == nil {
+ t.errorf("%s: Glob(%#q): bad pattern not detected", dir, glob+"nonexist/[]")
+ }
+
// Try to find a letter that appears in only some of the final names.
c := rune('a')
for ; c <= 'z'; c++ {