From aa43f1c56168edb907154626de2a088e308c9951 Mon Sep 17 00:00:00 2001 From: Aofei Sheng Date: Wed, 18 Nov 2020 17:13:42 +0800 Subject: [PATCH] fix: correct `RequestParamValue.String` --- request.go | 9 ++------- request_test.go | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/request.go b/request.go index 0450c5d..9cbba7d 100644 --- a/request.go +++ b/request.go @@ -3,7 +3,6 @@ package air import ( "context" "errors" - "fmt" "io" "mime/multipart" "net" @@ -744,12 +743,8 @@ func (rpv *RequestParamValue) Float64() (float64, error) { // if the rpv is not text-based. func (rpv *RequestParamValue) String() string { if rpv.s == nil { - if s, ok := rpv.i.(string); ok { - rpv.s = &s - } else { - s := fmt.Sprint(rpv.i) - rpv.s = &s - } + s, _ := rpv.i.(string) + rpv.s = &s } return *rpv.s diff --git a/request_test.go b/request_test.go index 126c9bb..6e2f42c 100644 --- a/request_test.go +++ b/request_test.go @@ -789,7 +789,7 @@ func TestRequestParamValueString(t *testing.T) { assert.Nil(t, rpv.s) s = rpv.String() - assert.Equal(t, "foobar", s) + assert.Empty(t, s) assert.NotNil(t, rpv.s) } @@ -809,7 +809,7 @@ func TestRequestParamValueBytes(t *testing.T) { assert.Nil(t, rpv.s) b = rpv.Bytes() - assert.Equal(t, []byte("foobar"), b) + assert.Nil(t, b) assert.NotNil(t, rpv.s) }