Skip to content

Commit 49e17d5

Browse files
authoredJun 18, 2022
Merge pull request #332 from harshanarayana/bug/GIT-331/fix-variable-shadown
GIT-331: fix shadowing key from the kv pair
2 parents 9c48b7d + e4329d2 commit 49e17d5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

‎internal/serialize/keyvalues.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ func KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
109109
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments
110110
// for the sake of performance. Keys with spaces,
111111
// special characters, etc. will break parsing.
112-
if k, ok := k.(string); ok {
112+
if sK, ok := k.(string); ok {
113113
// Avoid one allocation when the key is a string, which
114114
// normally it should be.
115-
b.WriteString(k)
115+
b.WriteString(sK)
116116
} else {
117117
b.WriteString(fmt.Sprintf("%s", k))
118118
}

‎internal/serialize/keyvalues_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ No whitespace.`,
140140
keysValues: []interface{}{"point-1", point{100, 200}, "point-2", emptyPoint},
141141
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>\"",
142142
},
143+
{
144+
keysValues: []interface{}{struct{ key string }{key: "k1"}, "value"},
145+
want: " {k1}=\"value\"",
146+
},
147+
{
148+
keysValues: []interface{}{1, "test"},
149+
want: " %!s(int=1)=\"test\"",
150+
},
151+
{
152+
keysValues: []interface{}{map[string]string{"k": "key"}, "value"},
153+
want: " map[k:key]=\"value\"",
154+
},
143155
}
144156

145157
for _, d := range testKVList {

0 commit comments

Comments
 (0)