From 58016d673d2892e03dd5c3421310334eac452037 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 19 Sep 2019 08:35:32 +0800 Subject: [PATCH] safe parse form and remove unnecessary parse on query --- .gitignore | 3 ++- form.go | 9 +++++++-- query.go | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 600d2d3..c7d0251 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vscode \ No newline at end of file +.vscode +*.log \ No newline at end of file diff --git a/form.go b/form.go index 275932f..3a3bb4b 100644 --- a/form.go +++ b/form.go @@ -35,7 +35,9 @@ func (f *Forms) Trimmed(key string) (string, error) { // Strings returns request form as strings func (f *Forms) Strings(key string) ([]string, error) { - (*http.Request)(f).ParseMultipartForm(32 << 20) + if (*http.Request)(f).Form == nil { + (*http.Request)(f).ParseMultipartForm(32 << 20) + } if v, ok := (*http.Request)(f).Form[key]; ok { return v, nil } @@ -114,7 +116,10 @@ func (f *Forms) MustTrimmed(key string, defaults ...string) string { // MustStrings returns request form as strings with default func (f *Forms) MustStrings(key string, defaults ...[]string) []string { - (*http.Request)(f).ParseMultipartForm(32 << 20) + if (*http.Request)(f).Form == nil { + (*http.Request)(f).ParseMultipartForm(32 << 20) + } + if v, ok := (*http.Request)(f).Form[key]; ok { return v } diff --git a/query.go b/query.go index 2972083..e9a356e 100644 --- a/query.go +++ b/query.go @@ -145,7 +145,6 @@ func (f *Queries) MustString(key string, defaults ...string) string { // MustStrings returns request form as strings with default func (f *Queries) MustStrings(key string, defaults ...[]string) []string { - (*http.Request)(f).ParseMultipartForm(32 << 20) if v, ok := f.Values()[key]; ok { return v } -- 2.40.1