Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl committed Dec 13, 2024
1 parent ccdc57c commit 46517cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions context_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"github.com/goravel/framework/support/str"
"io"
"net/http"
"reflect"
Expand All @@ -21,6 +20,7 @@ import (
contractsvalidate "github.com/goravel/framework/contracts/validation"
"github.com/goravel/framework/filesystem"
"github.com/goravel/framework/support/json"
"github.com/goravel/framework/support/str"
"github.com/goravel/framework/validation"
"github.com/spf13/cast"
)
Expand Down Expand Up @@ -295,7 +295,11 @@ func (r *ContextRequest) Input(key string, defaultValue ...string) string {

func (r *ContextRequest) InputArray(key string, defaultValue ...[]string) []string {
if valueFromHttpBody := r.getValueFromHttpBody(key); valueFromHttpBody != nil {
return cast.ToStringSlice(valueFromHttpBody)
if value := cast.ToStringSlice(valueFromHttpBody); value == nil {
return []string{}
} else {
return value
}
}

if value, exist := r.instance.GetQueryArray(key); exist {
Expand Down
6 changes: 4 additions & 2 deletions context_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,14 @@ func (s *ContextRequestSuite) TestInputMap_Default() {
func (s *ContextRequestSuite) TestInputMap_Empty() {
s.route.Post("/input-map/empty/{id}", func(ctx contractshttp.Context) contractshttp.Response {
return ctx.Response().Success().Json(contractshttp.Json{
"name": ctx.Request().InputMap("name"),
"name": ctx.Request().InputMap("name", map[string]string{
"a": "b",
}),
})
})

payload := strings.NewReader(`{
"id": {"a": "3", "b": "4"}
"name": {}
}`)
req, err := http.NewRequest("POST", "/input-map/empty/1?id=2", payload)
s.Require().Nil(err)
Expand Down

0 comments on commit 46517cb

Please sign in to comment.