From 328c898a3f0c50f8b0dd83aa37c84c099342a8a4 Mon Sep 17 00:00:00 2001 From: "Julien Tant (aider)" Date: Wed, 12 Feb 2025 12:41:14 -0700 Subject: [PATCH] refactor: Trim spaces from name and color in custom profile attribute select option constructor --- server/public/model/custom_profile_attributes.go | 9 ++++++--- server/public/model/custom_profile_attributes_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/public/model/custom_profile_attributes.go b/server/public/model/custom_profile_attributes.go index ee7a3a74881..bf4103dd4f1 100644 --- a/server/public/model/custom_profile_attributes.go +++ b/server/public/model/custom_profile_attributes.go @@ -3,7 +3,10 @@ package model -import "errors" +import ( + "errors" + "strings" +) const CustomProfileAttributesPropertyGroupName = "custom_profile_attributes" @@ -35,8 +38,8 @@ type CustomProfileAttributesSelectOption struct { func NewCustomProfileAttributeSelectOption(name, color string) CustomProfileAttributesSelectOption { return CustomProfileAttributesSelectOption{ ID: NewId(), - Name: name, - Color: color, + Name: strings.TrimSpace(name), + Color: strings.TrimSpace(color), } } diff --git a/server/public/model/custom_profile_attributes_test.go b/server/public/model/custom_profile_attributes_test.go index 33e1dbc912c..2d4cea2393f 100644 --- a/server/public/model/custom_profile_attributes_test.go +++ b/server/public/model/custom_profile_attributes_test.go @@ -18,6 +18,13 @@ func TestNewCustomProfileAttributeSelectOption(t *testing.T) { assert.Equal(t, "Test Option", option.Name) assert.Equal(t, "#FF0000", option.Color) }) + + t.Run("trims spaces from name and color", func(t *testing.T) { + option := NewCustomProfileAttributeSelectOption(" Test Option ", " #FF0000 ") + + assert.Equal(t, "Test Option", option.Name) + assert.Equal(t, "#FF0000", option.Color) + }) } func TestCustomProfileAttributeSelectOptionIsValid(t *testing.T) {