From d00e6a5695c14933081faaba74e92d95cca9377f Mon Sep 17 00:00:00 2001 From: yangquanshi Date: Wed, 21 May 2025 20:14:28 +0900 Subject: [PATCH 1/3] chore: fix some function names in comment (#4131) Signed-off-by: yangquanshi --- context_test.go | 4 ++-- middleware_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/context_test.go b/context_test.go index c2f82410..9857272c 100644 --- a/context_test.go +++ b/context_test.go @@ -1142,7 +1142,7 @@ func TestContextRenderNoContentXML(t *testing.T) { assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type")) } -// TestContextString tests that the response is returned +// TestContextRenderString tests that the response is returned // with Content-Type set to text/plain func TestContextRenderString(t *testing.T) { w := httptest.NewRecorder() @@ -1167,7 +1167,7 @@ func TestContextRenderNoContentString(t *testing.T) { assert.Equal(t, "text/plain; charset=utf-8", w.Header().Get("Content-Type")) } -// TestContextString tests that the response is returned +// TestContextRenderHTMLString tests that the response is returned // with Content-Type set to text/html func TestContextRenderHTMLString(t *testing.T) { w := httptest.NewRecorder() diff --git a/middleware_test.go b/middleware_test.go index eafc60ad..4390def7 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -203,7 +203,7 @@ func TestMiddlewareAbortHandlersChainAndNext(t *testing.T) { assert.Equal(t, "ACB", signature) } -// TestFailHandlersChain - ensure that Fail interrupt used middleware in fifo order as +// TestMiddlewareFailHandlersChain - ensure that Fail interrupt used middleware in fifo order as // as well as Abort func TestMiddlewareFailHandlersChain(t *testing.T) { // SETUP From 8f7c340577e19245827f7ba71ef3e0143cc7eeee Mon Sep 17 00:00:00 2001 From: Andreas Deininger Date: Wed, 21 May 2025 13:16:29 +0200 Subject: [PATCH 2/3] context_test.go: fix useless asserts (#4115) --- context_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/context_test.go b/context_test.go index 9857272c..ebcd08d4 100644 --- a/context_test.go +++ b/context_test.go @@ -885,10 +885,10 @@ func TestContextGetCookie(t *testing.T) { } func TestContextBodyAllowedForStatus(t *testing.T) { - assert.False(t, false, bodyAllowedForStatus(http.StatusProcessing)) - assert.False(t, false, bodyAllowedForStatus(http.StatusNoContent)) - assert.False(t, false, bodyAllowedForStatus(http.StatusNotModified)) - assert.True(t, true, bodyAllowedForStatus(http.StatusInternalServerError)) + assert.False(t, bodyAllowedForStatus(http.StatusProcessing)) + assert.False(t, bodyAllowedForStatus(http.StatusNoContent)) + assert.False(t, bodyAllowedForStatus(http.StatusNotModified)) + assert.True(t, bodyAllowedForStatus(http.StatusInternalServerError)) } type TestRender struct{} From 674522db91d637d179c16c372d87756ea26fa089 Mon Sep 17 00:00:00 2001 From: Kashiwa <13825170+ksw2000@users.noreply.github.com> Date: Wed, 21 May 2025 19:21:46 +0800 Subject: [PATCH 3/3] fix(time): binding time with empty value (#4103) * fix: binding time with empty value (#4098) * refact: simplify null-to-zero filling logic * test: add test for zeroUnixNanoTime --- binding/form_mapping.go | 10 +++++----- binding/form_mapping_test.go | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index 235692d2..c9f3197f 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -397,6 +397,11 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val timeFormat = time.RFC3339 } + if val == "" { + value.Set(reflect.ValueOf(time.Time{})) + return nil + } + switch tf := strings.ToLower(timeFormat); tf { case "unix", "unixmilli", "unixmicro", "unixnano": tv, err := strconv.ParseInt(val, 10, 64) @@ -420,11 +425,6 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val return nil } - if val == "" { - value.Set(reflect.ValueOf(time.Time{})) - return nil - } - l := time.Local if isUTC, _ := strconv.ParseBool(structField.Tag.Get("time_utc")); isUTC { l = time.UTC diff --git a/binding/form_mapping_test.go b/binding/form_mapping_test.go index 1277fd5f..45cd9297 100644 --- a/binding/form_mapping_test.go +++ b/binding/form_mapping_test.go @@ -183,11 +183,13 @@ func TestMapFormWithTag(t *testing.T) { func TestMappingTime(t *testing.T) { var s struct { - Time time.Time - LocalTime time.Time `time_format:"2006-01-02"` - ZeroValue time.Time - CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"` - UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"` + Time time.Time + LocalTime time.Time `time_format:"2006-01-02"` + ZeroValue time.Time + ZeroUnixTime time.Time `time_format:"unix"` + ZeroUnixNanoTime time.Time `time_format:"unixnano"` + CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"` + UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"` } var err error @@ -195,11 +197,13 @@ func TestMappingTime(t *testing.T) { require.NoError(t, err) err = mapForm(&s, map[string][]string{ - "Time": {"2019-01-20T16:02:58Z"}, - "LocalTime": {"2019-01-20"}, - "ZeroValue": {}, - "CSTTime": {"2019-01-20"}, - "UTCTime": {"2019-01-20"}, + "Time": {"2019-01-20T16:02:58Z"}, + "LocalTime": {"2019-01-20"}, + "ZeroValue": {}, + "ZeroUnixTime": {}, + "ZeroUnixNanoTime": {}, + "CSTTime": {"2019-01-20"}, + "UTCTime": {"2019-01-20"}, }) require.NoError(t, err) @@ -207,6 +211,8 @@ func TestMappingTime(t *testing.T) { assert.Equal(t, "2019-01-20 00:00:00 +0100 CET", s.LocalTime.String()) assert.Equal(t, "2019-01-19 23:00:00 +0000 UTC", s.LocalTime.UTC().String()) assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", s.ZeroValue.String()) + assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", s.ZeroUnixTime.UTC().String()) + assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", s.ZeroUnixNanoTime.UTC().String()) assert.Equal(t, "2019-01-20 00:00:00 +0800 CST", s.CSTTime.String()) assert.Equal(t, "2019-01-19 16:00:00 +0000 UTC", s.CSTTime.UTC().String()) assert.Equal(t, "2019-01-20 00:00:00 +0000 UTC", s.UTCTime.String())