From 3e2e065d607aee07d4b2edb278f06fcaa75f6448 Mon Sep 17 00:00:00 2001 From: Hugon Szaniewski Date: Thu, 10 Oct 2024 16:27:33 +0200 Subject: [PATCH] Fix --- gdpr/protect_ip.go | 17 ++--------------- gdpr/protect_ip_test.go | 4 ++-- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/gdpr/protect_ip.go b/gdpr/protect_ip.go index 9a54fee..24939d9 100644 --- a/gdpr/protect_ip.go +++ b/gdpr/protect_ip.go @@ -3,7 +3,6 @@ package gdpr import ( "encoding/binary" "net" - "net/netip" "github.com/msales/gox/netx" ) @@ -23,26 +22,14 @@ func ProtectIP[T IP](ip T) string { return "" } - // if IP is v6, we don't do anything with it. + // if IP is v6, change last 2 octets of ip. if cIP.To4() == nil { - - // if IPv6 is local we don't do anything - if cIP.String() == "::1" { - return cIP.String() - } - cIP[12] = 0 cIP[13] = 0 cIP[14] = 0 cIP[15] = 0 - addr, err := netip.ParseAddr(cIP.String()) - // if there is an error, we don't do anything, we return empty value because something is wrong with passed ip - if err != nil { - return "" - } - - return addr.StringExpanded() + return cIP.String() } // change last octet of IP v4 to 0 and guard diff --git a/gdpr/protect_ip_test.go b/gdpr/protect_ip_test.go index 1221192..025439a 100644 --- a/gdpr/protect_ip_test.go +++ b/gdpr/protect_ip_test.go @@ -100,12 +100,12 @@ func Test_ProtectIP_String(t *testing.T) { { name: "local ip v6", ip: "::1", - want: "::1", + want: "::", }, { name: "raw ip v6", ip: "2001:0000:130F:0000:0000:09C0:876A:130B", - want: "2001:0000:130f:0000:0000:09c0:0000:0000", + want: "2001:0:130f::9c0:0:0", }, } for _, tt := range tests {