From 1970d45aeb009e6cf9978694778971e846425837 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Sat, 14 Nov 2026 05:52:07 -0300 Subject: [PATCH] fix: find groups declared with upper case letters Configuration keys are stored in lower case, so a group declared as W1 was only found with "-n w1", while "-n Dom" finds profile Dom. Fall back to the lower case name when looking up a group. Signed-off-by: Lucas Barros --- config/config.go | 15 +++++++++++++-- config/config_group_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 5d1311a93..b044d921c 100644 --- a/config/config.go +++ b/config/config.go @@ -517,7 +517,7 @@ func (c *Config) HasProfileGroup(groupKey string) bool { if err := c.loadGroups(); err != nil { return false } - _, ok := c.cached.groups[groupKey] + _, ok := c.lookupGroup(groupKey) return ok } @@ -527,13 +527,24 @@ func (c *Config) GetProfileGroup(groupKey string) (*Group, error) { return nil, err } - group, ok := c.cached.groups[groupKey] + group, ok := c.lookupGroup(groupKey) if !ok { return nil, ErrNotFound } return group, nil } +// lookupGroup finds a loaded group by name. The configuration keys are +// stored in lower case, so a group declared as "W1" is found with "W1" too, +// like profiles are. +func (c *Config) lookupGroup(groupKey string) (*Group, bool) { + if group, ok := c.cached.groups[groupKey]; ok { + return group, true + } + group, ok := c.cached.groups[strings.ToLower(groupKey)] + return group, ok +} + // GetProfileGroups returns all groups from the configuration // // If the groups section does not exist, it returns an empty map diff --git a/config/config_group_test.go b/config/config_group_test.go index f0f4d1265..6d9769e80 100644 --- a/config/config_group_test.go +++ b/config/config_group_test.go @@ -223,3 +223,40 @@ groups: }) } } + +func TestGetProfileGroupMixedCase(t *testing.T) { + testData := []testGroupData{ + { + FormatTOML, + ` +[groups] +W1 = ["Dom", "Ha"] +`, + }, + { + FormatYAML, + ` +version: 2 +groups: + W1: + profiles: [Dom, Ha] +`, + }, + } + + for _, testItem := range testData { + t.Run(testItem.format, func(t *testing.T) { + c, err := Load(bytes.NewBufferString(testItem.config), testItem.format) + require.NoError(t, err) + + for _, name := range []string{"W1", "w1"} { + assert.True(t, c.HasProfileGroup(name), name) + + group, err := c.GetProfileGroup(name) + require.NoError(t, err, name) + assert.Equal(t, []string{"Dom", "Ha"}, group.Profiles) + } + assert.False(t, c.HasProfileGroup("W2")) + }) + } +}