Browse Source

Safe parse form and remove unnecessary parse on query (#63)

tags/v0.6.2
Lunny Xiao Gitea 2 months ago
parent
commit
8127f80b41
3 changed files with 9 additions and 4 deletions
  1. +2
    -1
      .gitignore
  2. +7
    -2
      form.go
  3. +0
    -1
      query.go

+ 2
- 1
.gitignore View File

@@ -1 +1,2 @@
.vscode
.vscode
*.log

+ 7
- 2
form.go View File

@@ -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
}


+ 0
- 1
query.go View File

@@ -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
}


Loading…
Cancel
Save