Skip to content

Commit

Permalink
Merge pull request #622 from DanielCKennedy/skippable_single_quote_5
Browse files Browse the repository at this point in the history
Avoid parsing single quote empty inputs
  • Loading branch information
k8s-ci-robot authored Aug 8, 2023
2 parents f80d3ea + 72715c3 commit 3a9a8a7
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 @@ -154,7 +154,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 @@ -307,3 +307,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 3a9a8a7

Please sign in to comment.