diff --git a/gdpr/protect_device_id.go b/gdpr/protect_device_id.go index bf8ea15..949ba53 100644 --- a/gdpr/protect_device_id.go +++ b/gdpr/protect_device_id.go @@ -10,9 +10,12 @@ const ( // ProtectDeviceID hides last two character from passed device id and returns string with protected value func ProtectDeviceID(val string) string { - lowered := strings.ToLower(val) + if val == "" { + return val + } - if val == "" || lowered == unknownValue || lowered == nonAvailableValue { + lowered := strings.ToLower(val) + if lowered == unknownValue || lowered == nonAvailableValue { return val } diff --git a/gdpr/protect_device_id_test.go b/gdpr/protect_device_id_test.go index 53f71c1..fb94f80 100644 --- a/gdpr/protect_device_id_test.go +++ b/gdpr/protect_device_id_test.go @@ -86,3 +86,48 @@ func BenchmarkProtectDeviceID(b *testing.B) { ProtectDeviceID(strconv.Itoa(i)) } } + +func BenchmarkProtectDeviceID_Empty(b *testing.B) { + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + ProtectDeviceID("") + } +} + +func BenchmarkProtectDeviceID_NA_Mixed(b *testing.B) { + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + ProtectDeviceID("N/a") + } +} + +func BenchmarkProtectDeviceID_NA_Lower(b *testing.B) { + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + ProtectDeviceID("n/a") + } +} + +func BenchmarkProtectDeviceID_Unknown_Mixed(b *testing.B) { + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + ProtectDeviceID("Unknown") + } +} + +func BenchmarkProtectDeviceID_Unknown_Lower(b *testing.B) { + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + ProtectDeviceID("unknown") + } +}