Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,11 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in
func matchRegexp(rx interface{}, str interface{}) bool {
var r *regexp.Regexp
if rr, ok := rx.(*regexp.Regexp); ok {
// A typed nil passes the type assertion, and MatchString would then
// dereference it. There is no pattern, so nothing can match.
if rr == nil {
return false
}
r = rr
} else {
r = regexp.MustCompile(fmt.Sprint(rx))
Expand Down
15 changes: 15 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,21 @@ func TestNeverFailQuickly(t *testing.T) {
False(t, Never(mockT, condition, 100*time.Millisecond, time.Second))
}

// A typed nil *regexp.Regexp passes the type assertion in matchRegexp and is
// then dereferenced, so Regexp and NotRegexp panic instead of reporting a
// result.
func TestRegexpNilTypedRegexp(t *testing.T) {
t.Parallel()

var rx *regexp.Regexp
mockT := new(testing.T)

NotPanics(t, func() {
False(t, Regexp(mockT, rx, "anything"))
})
True(t, NotRegexp(t, rx, "anything"))
}

func Test_validateEqualArgs(t *testing.T) {
t.Parallel()

Expand Down
Loading