mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(maputil): validate MapToStruct inputs before reflection (#375)
This commit is contained in:
1 parent
b282ada39e
commit
18e9bc9cda
2 files changed
+24
No files matched your search
@@ -11,6 +11,23 @@ import (
|
||||
"github.com/duke-git/lancet/v2/internal"
|
||||
)
|
||||
|
||||
func TestMapToStructInvalidInputs(t *testing.T) {
|
||||
var nilTarget *struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
for _, dst := range []any{nil, nilTarget, 1, &[]int{}} {
|
||||
if err := MapToStruct(map[string]any{"name": "value"}, dst); err == nil {
|
||||
t.Errorf("expected an error for %T", dst)
|
||||
}
|
||||
}
|
||||
var dst struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
if err := MapToStruct(map[string]any{"name": nil}, &dst); err == nil {
|
||||
t.Error("expected an error for an incompatible nil value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestKeys(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in new issue
Block a user