mirror of https://github.com/stretchr/testify.git
Reverse ConvertibleTo check to avoid panic
in `ObjectsAreEqual`, `expectedValue.Convert(actualType)` was being called when `actualType.ConvertibleTo(reflect.TypeOf(expected))` was true. This was a problem for situations such as when expected was an int and actual was a string, since ints are `ConvertibleTo` strings, but the reverse is not true. Changing the ConvertibleTo check to `expectedValue.Type().ConvertibleTo(actualType)` solves the issue.pull/115/head
parent
85138dbfa5
commit
02a8ab057b
|
@ -37,8 +37,8 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
|
|||
}
|
||||
|
||||
actualType := reflect.TypeOf(actual)
|
||||
if actualType.ConvertibleTo(reflect.TypeOf(expected)) {
|
||||
expectedValue := reflect.ValueOf(expected)
|
||||
expectedValue := reflect.ValueOf(expected)
|
||||
if expectedValue.Type().ConvertibleTo(actualType) {
|
||||
// Attempt comparison after type conversion
|
||||
if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) {
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue