Skip to content

Commit

Permalink
Merge pull request #332 from harshanarayana/bug/GIT-331/fix-variable-…
Browse files Browse the repository at this point in the history
…shadown

GIT-331: fix shadowing key from the kv pair
  • Loading branch information
k8s-ci-robot committed Jun 18, 2022
2 parents 9c48b7d + e4329d2 commit 49e17d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/serialize/keyvalues.go
Expand Up @@ -109,10 +109,10 @@ func KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments
// for the sake of performance. Keys with spaces,
// special characters, etc. will break parsing.
if k, ok := k.(string); ok {
if sK, ok := k.(string); ok {
// Avoid one allocation when the key is a string, which
// normally it should be.
b.WriteString(k)
b.WriteString(sK)
} else {
b.WriteString(fmt.Sprintf("%s", k))
}
Expand Down
12 changes: 12 additions & 0 deletions internal/serialize/keyvalues_test.go
Expand Up @@ -140,6 +140,18 @@ No whitespace.`,
keysValues: []interface{}{"point-1", point{100, 200}, "point-2", emptyPoint},
want: " point-1=\"x=100, y=200\" point-2=\"<panic: value method k8s.io/klog/v2/internal/serialize_test.point.String called using nil *point pointer>\"",
},
{
keysValues: []interface{}{struct{ key string }{key: "k1"}, "value"},
want: " {k1}=\"value\"",
},
{
keysValues: []interface{}{1, "test"},
want: " %!s(int=1)=\"test\"",
},
{
keysValues: []interface{}{map[string]string{"k": "key"}, "value"},
want: " map[k:key]=\"value\"",
},
}

for _, d := range testKVList {
Expand Down

0 comments on commit 49e17d5

Please sign in to comment.