Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIT-331: fix shadowing key from the kv pair #332

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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