mirror of
https://github.com/golang/go
synced 2024-11-25 13:07:57 -07:00
path/filepath: Panic in Match when parsing invalid character range.
Fixes #5668. R=golang-dev, rsc, r CC=golang-dev https://golang.org/cl/12001056
This commit is contained in:
parent
53b61057b2
commit
27032fddee
@ -132,6 +132,12 @@ func matchChunk(chunk, s string) (rest string, ok bool, err error) {
|
||||
r, n := utf8.DecodeRuneInString(s)
|
||||
s = s[n:]
|
||||
chunk = chunk[1:]
|
||||
// We can't end right after '[', we're expecting at least
|
||||
// a closing bracket and possibly a caret.
|
||||
if len(chunk) == 0 {
|
||||
err = ErrBadPattern
|
||||
return
|
||||
}
|
||||
// possibly negated
|
||||
negated := chunk[0] == '^'
|
||||
if negated {
|
||||
|
@ -65,6 +65,11 @@ var matchTests = []MatchTest{
|
||||
{"[-x]", "a", false, ErrBadPattern},
|
||||
{"\\", "a", false, ErrBadPattern},
|
||||
{"[a-b-c]", "a", false, ErrBadPattern},
|
||||
{"[", "a", false, ErrBadPattern},
|
||||
{"[^", "a", false, ErrBadPattern},
|
||||
{"[^bc", "a", false, ErrBadPattern},
|
||||
{"a[", "a", false, nil},
|
||||
{"a[", "ab", false, ErrBadPattern},
|
||||
{"*x", "xxx", true, nil},
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,11 @@ var matchTests = []MatchTest{
|
||||
{"[-x]", "a", false, ErrBadPattern},
|
||||
{"\\", "a", false, ErrBadPattern},
|
||||
{"[a-b-c]", "a", false, ErrBadPattern},
|
||||
{"[", "a", false, ErrBadPattern},
|
||||
{"[^", "a", false, ErrBadPattern},
|
||||
{"[^bc", "a", false, ErrBadPattern},
|
||||
{"a[", "a", false, nil},
|
||||
{"a[", "ab", false, ErrBadPattern},
|
||||
{"*x", "xxx", true, nil},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user