Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in getting array type parameters in get method #1255

Open
2 tasks
soul-key opened this issue Apr 19, 2024 · 0 comments
Open
2 tasks

Error in getting array type parameters in get method #1255

soul-key opened this issue Apr 19, 2024 · 0 comments

Comments

@soul-key
Copy link

soul-key commented Apr 19, 2024

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

The GetFormValues() method in the rest/https/util.go file is unable to obtain array parameters due to r.Form. Get(name) will force the first value of the array parameter to be returned, and can only be a string. This method should be changed to
r. Form["name"]

Code sample, to showcase or reproduce:

① error code

func GetFormValues(r *http.Request) (map[string]any, error) {
	if err := r.ParseForm(); err != nil {
		return nil, err
	}

	if err := r.ParseMultipartForm(maxMemory); err != nil {
		if err != http.ErrNotMultipart {
			return nil, err
		}
	}

	params := make(map[string]any, len(r.Form))
	for name := range r.Form {
		formValue := r.Form.Get(name)
		if len(formValue) > 0 {
			params[name] = formValue
		}
	}

	return params, nil
}

right code

func GetFormValues(r *http.Request) (map[string]any, error) {
	if err := r.ParseForm(); err != nil {
		return nil, err
	}

	if err := r.ParseMultipartForm(maxMemory); err != nil {
		if err != http.ErrNotMultipart {
			return nil, err
		}
	}

	params := make(map[string]any, len(r.Form))
	for name := range r.Form {
		if len( r.Form[name]) > 1 {
			params[name] =  r.Form[name]
		}else{
		        formValue := r.Form.Get(name)
                        if len(formValue) >0 {
                              params[name] = formValue
		       }
                }
	}

	return params, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant