Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent nil-dereference in format.Object for boxed nil error #681

Merged
merged 1 commit into from Jul 22, 2023

Conversation

matthchr
Copy link
Contributor

@matthchr matthchr commented Jul 14, 2023

This fixes #680

@@ -259,7 +259,7 @@ func Object(object interface{}, indentation uint) string {
indent := strings.Repeat(Indent, int(indentation))
value := reflect.ValueOf(object)
commonRepresentation := ""
if err, ok := object.(error); ok {
if err, ok := object.(error); ok && !isNilValue(value) { // isNilValue check needed here to avoid nil deref due to boxed nil
Copy link
Contributor Author

@matthchr matthchr Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to remove this comment if you feel it's unneeded.

@onsi
Copy link
Owner

onsi commented Jul 22, 2023

this looks good to me! thanks :)

@onsi onsi merged commit 3b31fc3 into onsi:master Jul 22, 2023
6 checks passed
@matthchr matthchr deleted the feature/boxed-nil-error-fix branch July 22, 2023 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boxed errors that are nil can trigger a panic in format.Object
2 participants