aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2024-06-24 07:57:45 -0700
committerGopher Robot <gobot@golang.org>2024-06-24 15:28:56 +0000
commit085cf0fcdc4faa2f473839f8cc1860ec5bcf97a3 (patch)
tree31de0a7a376cdd931c290453c04d981ddb595971 /src/net
parent740043f516f716fe359ffd3bd76f1a30a9aa5eec (diff)
downloadgo-085cf0fcdc4faa2f473839f8cc1860ec5bcf97a3.tar.xz
net/netip: add test that Compare and reflect.DeepEqual match
Updates #68113 Change-Id: I1107686ef364f77f48f55534ea8ec68d1785e1e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/594375 Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/net')
-rw-r--r--src/net/netip/netip_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/net/netip/netip_test.go b/src/net/netip/netip_test.go
index 94c70f2290..e1a0a83f64 100644
--- a/src/net/netip/netip_test.go
+++ b/src/net/netip/netip_test.go
@@ -893,6 +893,15 @@ func TestAddrLessCompare(t *testing.T) {
{mustIP("::1%a"), mustIP("::1%b"), true},
{mustIP("::1%a"), mustIP("::1%a"), false},
{mustIP("::1%b"), mustIP("::1%a"), false},
+
+ // For Issue 68113, verify that an IPv4 address and a
+ // v4-mapped-IPv6 address differing only in their zone
+ // pointer are unequal via all three of
+ // ==/Compare/reflect.DeepEqual. In Go 1.22 and
+ // earlier, these were accidentally equal via
+ // DeepEqual due to their zone pointers (z) differing
+ // but pointing to identical structures.
+ {mustIP("::ffff:11.1.1.12"), mustIP("11.1.1.12"), false},
}
for _, tt := range tests {
got := tt.a.Less(tt.b)
@@ -920,6 +929,12 @@ func TestAddrLessCompare(t *testing.T) {
t.Errorf("Less(%q, %q) was correctly %v, but so was Less(%q, %q)", tt.a, tt.b, got, tt.b, tt.a)
}
}
+
+ // Also check reflect.DeepEqual. See issue 68113.
+ deepEq := reflect.DeepEqual(tt.a, tt.b)
+ if (cmp == 0) != deepEq {
+ t.Errorf("%q and %q differ in == (%v) vs reflect.DeepEqual (%v)", tt.a, tt.b, cmp == 0, deepEq)
+ }
}
// And just sort.