Skip to content

assert: reject wrapped signed values in EqualValues - #1975

Open
lowgame wants to merge 1 commit into
stretchr:masterfrom
lowgame:fix-equalvalues-signedness-4e41dd2d
Open

lowgame wants to merge 1 commit into
stretchr:masterfrom
lowgame:fix-equalvalues-signedness-4e41dd2d

Conversation

@lowgame

@lowgame lowgame commented Sep 30, 2026

Copy link
Copy Markdown

Summary

Prevent EqualValues from treating a negative signed integer as an equal unsigned integer after wrapping conversion.

Changes

  • Return unequal before numeric conversion when one operand is a negative signed integer and the other is unsigned.
  • Add regression cases for both operand orders.

Motivation

ObjectsAreEqualValues(int64(-1), uint64(math.MaxUint64)) and the reverse order both returned true. The size-based numeric conversion converted -1 to MaxUint64, creating a false positive even though the numeric values differ.

Before the fix:

$ go test ./assert -run '^TestObjectsAreEqualValues$' -count=1
--- FAIL: TestObjectsAreEqualValues
    --- FAIL: TestObjectsAreEqualValues/ObjectsAreEqualValues(-1,_0xffffffffffffffff)
    --- FAIL: TestObjectsAreEqualValues/ObjectsAreEqualValues(0xffffffffffffffff,_-1)
FAIL

After the fix:

$ go test ./assert -run '^TestObjectsAreEqualValues$' -count=1
ok github.com/stretchr/testify/assert

$ go test ./assert -count=1
ok github.com/stretchr/testify/assert

$ GOTOOLCHAIN=go1.25.0 ./.ci.gogenerate.sh
passed

$ GOTOOLCHAIN=go1.25.0 ./.ci.gofmt.sh
passed

$ GOTOOLCHAIN=go1.25.0 ./.ci.govet.sh
passed

$ GOTOOLCHAIN=go1.25.0 go test -race ./...
passed (all packages)

Related issues

No related issue found.

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.

1 participant