From 18298b966f0c31ee638f5abb6188855aab3697c4 Mon Sep 17 00:00:00 2001 From: Hugon Szaniewski Date: Thu, 10 Oct 2024 16:23:18 +0200 Subject: [PATCH] small fix --- gdpr/protect_device_id.go | 8 +++++--- gdpr/protect_device_id_test.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gdpr/protect_device_id.go b/gdpr/protect_device_id.go index 7ce743b..20a9d7d 100644 --- a/gdpr/protect_device_id.go +++ b/gdpr/protect_device_id.go @@ -14,12 +14,14 @@ func ProtectDeviceID(val string) string { l := len(r) // If someone passes string with less than 2 characters, we don't protect it. + c := 2 if l < 2 { - return val + c = l } - r[l-1] = hiddenRune - r[l-2] = hiddenRune + for i := 1; i <= c; i++ { + r[l-i] = hiddenRune + } return string(r) } diff --git a/gdpr/protect_device_id_test.go b/gdpr/protect_device_id_test.go index 8b1cc14..9cdd40f 100644 --- a/gdpr/protect_device_id_test.go +++ b/gdpr/protect_device_id_test.go @@ -36,7 +36,7 @@ func Test_ProtectDeviceID(t *testing.T) { { name: "string with less than 2 chars", value: "1", - want: "1", + want: "*", }, } for _, tt := range tests {