Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func bindData(destination any, data map[string][]string, tag string, dataFiles m
fm := &meta.fields[fi]
structField := val.Field(fm.index)
if fm.anonymous {
if structField.Kind() == reflect.Pointer {
if structField.Kind() == reflect.Pointer && structField.Type().Elem().Kind() == reflect.Struct {
structField = structField.Elem()
}
}
Expand Down
37 changes: 37 additions & 0 deletions bind_embedded_scalar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors

package echo

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

type EmbeddedIdentifier int

func TestBindEmbeddedScalarPointer(t *testing.T) {
identifier := EmbeddedIdentifier(7)
target := struct {
*EmbeddedIdentifier `query:"id"`
}{EmbeddedIdentifier: &identifier}
c := New().NewContext(httptest.NewRequest(http.MethodGet, "/?id=42", nil), httptest.NewRecorder())

if assert.NoError(t, c.Bind(&target)) {
assert.Equal(t, EmbeddedIdentifier(42), *target.EmbeddedIdentifier)
}
}

func TestBindEmbeddedScalarValue(t *testing.T) {
target := struct {
EmbeddedIdentifier `query:"id"`
}{}
c := New().NewContext(httptest.NewRequest(http.MethodGet, "/?id=42", nil), httptest.NewRecorder())

if assert.NoError(t, c.Bind(&target)) {
assert.Equal(t, EmbeddedIdentifier(42), target.EmbeddedIdentifier)
}
}
Loading