mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
case sensitive matching prioritized
This commit is contained in:
parent
01cfe83efe
commit
6007218835
13
bind.go
13
bind.go
@ -104,12 +104,12 @@ func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag
|
||||
}
|
||||
}
|
||||
|
||||
var inputValue []string
|
||||
var exists bool
|
||||
|
||||
// Go json.Unmarshal supports case insensitive binding. However the url
|
||||
// params are bound case sensitive which is inconsistent. To fix this
|
||||
// we must check all of the map values in a case-insensitive search.
|
||||
inputValue, exists := data[inputFieldName]
|
||||
if !exists {
|
||||
// Go json.Unmarshal supports case insensitive binding. However the
|
||||
// url params are bound case sensitive which is inconsistent. To
|
||||
// fix this we must check all of the map values in a
|
||||
// case-insensitive search.
|
||||
inputFieldName = strings.ToLower(inputFieldName)
|
||||
for k, v := range data {
|
||||
if strings.ToLower(k) == inputFieldName {
|
||||
@ -118,6 +118,7 @@ func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !exists {
|
||||
continue
|
||||
|
13
bind_test.go
13
bind_test.go
@ -165,6 +165,19 @@ func TestBindQueryParamsCaseInsensitive(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBindQueryParamsCaseSensitivePrioritized(t *testing.T) {
|
||||
e := New()
|
||||
req := httptest.NewRequest(GET, "/?id=1&ID=2&NAME=Jon+Snow&name=Jon+Doe", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
u := new(user)
|
||||
err := c.Bind(u)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, 1, u.ID)
|
||||
assert.Equal(t, "Jon Doe", u.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBindUnmarshalParam(t *testing.T) {
|
||||
e := New()
|
||||
req := httptest.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil)
|
||||
|
Loading…
Reference in New Issue
Block a user