pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/labstack/echo/pull/2844/files

heet" href="https://github.githubassets.com/assets/github-cf976967feea1e66.css" /> add DefaultBinder negative-path tests (multipart & non-struct) by miladev95 · Pull Request #2844 · labstack/echo · GitHub
Skip to content
Open
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
41 changes: 39 additions & 2 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ func TestTimeFormatBinding(t *testing.T) {
DateTimeLocal time.Time `form:"datetime_local" format:"2006-01-02T15:04"`
Date time.Time `query:"date" format:"2006-01-02"`
CustomFormat time.Time `form:"custom" format:"01/02/2006 15:04:05"`
DefaultTime time.Time `form:"default_time"` // No format tag - should use default parsing
DefaultTime time.Time `form:"default_time"` // No format tag - should use default parsing
PtrTime *time.Time `query:"ptr_time" format:"2006-01-02"`
}

Expand Down Expand Up @@ -1623,7 +1623,7 @@ func TestTimeFormatBinding(t *testing.T) {
{
name: "nok, wrong format should fail",
contentType: MIMEApplicationForm,
data: "datetime_local=2023-12-25", // Missing time part
data: "datetime_local=2023-12-25", // Missing time part
expectError: true,
},
}
Expand Down Expand Up @@ -1684,3 +1684,40 @@ func TestTimeFormatBinding(t *testing.T) {
})
}
}

func TestIsFieldMultipartFile_NonPointer_FileHeader_ReturnsError(t *testing.T) {
ok, err := isFieldMultipartFile(reflect.TypeOf(multipart.FileHeader{}))
assert.True(t, ok)
assert.Error(t, err)
assert.Contains(t, err.Error(), "binding to multipart.FileHeader struct is not supported")

// pointer type should be ok and no error
ok, err = isFieldMultipartFile(reflect.TypeOf((*multipart.FileHeader)(nil)))
assert.True(t, ok)
assert.NoError(t, err)
}

func TestSetMultipartFileHeaderTypes_NoFiles_ReturnsFalse(t *testing.T) {
var s struct {
Files []multipart.FileHeader
}
v := reflect.ValueOf(&s).Elem().Field(0)
ok := setMultipartFileHeaderTypes(v, "files", map[string][]*multipart.FileHeader{})
assert.False(t, ok)
}

func TestDefaultBinder_bindData_NonStruct_ReturnsError(t *testing.T) {
b := &DefaultBinder{}
// destination is pointer to slice (non-struct), tag is form -> should return error
err := b.bindData(&[]int{}, map[string][]string{"a": {"1"}}, "form", nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), "binding element must be a struct")

// for param/query/header tag should return nil (handled earlier)
err = b.bindData(&[]int{}, map[string][]string{"a": {"1"}}, "param", nil)
assert.NoError(t, err)

// also header
err = b.bindData(&[]int{}, map[string][]string{"a": {"1"}}, "header", nil)
assert.NoError(t, err)
}
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy