Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsknadaj committed Oct 10, 2024
1 parent 75aa499 commit 2dd2662
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions gdpr/protect_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ func ProtectIP[T IP](ip T) string {
switch cIP := any(ip).(type) {
// Every other type should end up in this case.
case net.IP:
// if ip is somehow empty or nil, return empty string
if cIP == nil || len(cIP) == 0 {

Check failure on line 22 in gdpr/protect_ip.go

View workflow job for this annotation

GitHub Actions / Test (1.21)

should omit nil check; len() for net.IP is defined as zero (S1009)

Check failure on line 22 in gdpr/protect_ip.go

View workflow job for this annotation

GitHub Actions / Test (1.21.x)

should omit nil check; len() for net.IP is defined as zero (S1009)
return ""
}

// if IP is v6, we don't do anything with it.
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
Expand All @@ -34,11 +45,6 @@ func ProtectIP[T IP](ip T) string {
return addr.StringExpanded()
}

// if ip is somehow empty, return empty string
if len(cIP) == 0 {
return ""
}

// change last octet of IP v4 to 0 and guard
cIP[15] = 0
return cIP.String()
Expand Down

0 comments on commit 2dd2662

Please sign in to comment.