Skip to content

Commit

Permalink
Merge pull request #237 from yuzhiquan/fix-byte-array-display
Browse files Browse the repository at this point in the history
Fix byte array display in InfoS and ErrorS
  • Loading branch information
k8s-ci-robot committed May 11, 2021
2 parents 0cc9b83 + 59f7cb5 commit 4c0ac5a
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 4c0ac5a

Please sign in to comment.