Skip to content

Commit

Permalink
Avoid parsing single quote empty inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCKennedy committed Aug 7, 2023
1 parent 2787f5e commit fb3af2c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/mapper/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func ParseMap(m map[string]string) (userMappings []config.UserMapping, roleMappi

func isSkippable(data string) bool {
trimmed := strings.TrimSpace(data)
return trimmed == "" || trimmed == "``" || trimmed == "\"\""
return trimmed == "" || trimmed == "``" || trimmed == "\"\"" || trimmed == "''"
}

func EncodeMap(userMappings []config.UserMapping, roleMappings []config.RoleMapping, awsAccounts []string) (m map[string]string, err error) {
Expand Down
22 changes: 22 additions & 0 deletions pkg/mapper/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,25 @@ func TestBadParseMap(t *testing.T) {
t.Fatalf("unexpected %v != %v", emptyMap, m2)
}
}

func TestBadParseMapSingleQuote(t *testing.T) {
m1 := map[string]string{
"mapAccounts": `''`,
"mapRoles": `''`,
"mapUsers": `''`,
}

u, r, a, err := ParseMap(m1)
if err != nil {
t.Fatal(err)
}

m2, err := EncodeMap(u, r, a)
if err != nil {
t.Fatal(err)
}
emptyMap := map[string]string{}
if !reflect.DeepEqual(emptyMap, m2) {
t.Fatalf("unexpected %v != %v", emptyMap, m2)
}
}

0 comments on commit fb3af2c

Please sign in to comment.