Skip to content

Commit

Permalink
fix byte array display in InfoS and ErrorS
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhiquan committed May 11, 2021
1 parent 0cc9b83 commit 59f7cb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions klog.go
Expand Up @@ -825,6 +825,8 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
switch v.(type) {
case string, error:
b.WriteString(fmt.Sprintf("%s=%q", k, v))
case []byte:
b.WriteString(fmt.Sprintf("%s=%+q", k, v))
default:
if _, ok := v.(fmt.Stringer); ok {
b.WriteString(fmt.Sprintf("%s=%q", k, v))
Expand Down
8 changes: 8 additions & 0 deletions klog_test.go
Expand Up @@ -1067,6 +1067,14 @@ func TestKvListFormat(t *testing.T) {
keysValues: []interface{}{"pod", "kubedns", "values", []string{"deployment", "svc", "configmap"}},
want: " pod=\"kubedns\" values=[deployment svc configmap]",
},
{
keysValues: []interface{}{"pod", "kubedns", "bytes", []byte("test case for byte array")},
want: " pod=\"kubedns\" bytes=\"test case for byte array\"",
},
{
keysValues: []interface{}{"pod", "kubedns", "bytes", []byte("��=� ⌘")},
want: " pod=\"kubedns\" bytes=\"\\ufffd\\ufffd=\\ufffd \\u2318\"",
},
{
keysValues: []interface{}{"pod", "kubedns", "maps", map[string]int{"three": 4}},
want: " pod=\"kubedns\" maps=map[three:4]",
Expand Down

0 comments on commit 59f7cb5

Please sign in to comment.