Skip to content

Commit

Permalink
Merge pull request #191 from champly/fix-attachment-lost-nil
Browse files Browse the repository at this point in the history
fix get attachment lost nil key
  • Loading branch information
AlexStocks committed May 21, 2020
2 parents 62debf0 + 2bf7e9c commit 8dcaa20
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions request.go
Expand Up @@ -337,6 +337,11 @@ func ToMapStringString(origin map[interface{}]interface{}) map[string]string {
dest := make(map[string]string)
for k, v := range origin {
if kv, ok := k.(string); ok {
if v == nil {
dest[kv] = ""
continue
}

if vv, ok := v.(string); ok {
dest[kv] = vv
}
Expand Down
35 changes: 35 additions & 0 deletions request_test.go
Expand Up @@ -18,6 +18,7 @@
package hessian

import (
"reflect"
"testing"
"time"
)
Expand Down Expand Up @@ -80,3 +81,37 @@ func TestDescRegex(t *testing.T) {
assert.Equal(t, "[Ljava/lang/String;", results[0])
assert.Equal(t, "[I", results[1])
}

func TestIssue192(t *testing.T) {
type args struct {
origin map[interface{}]interface{}
}
tests := []struct {
name string
args args
want map[string]string
}{
{
name: "not null",
args: args{
origin: map[interface{}]interface{}{
"1": nil,
"2": "3",
"": "",
},
},
want: map[string]string{
"1": "",
"2": "3",
"": "",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ToMapStringString(tt.args.origin); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ToMapStringString() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 8dcaa20

Please sign in to comment.