[Go-Server] Use ParseQuery For Parsing Query Parameters (#17585)

* Uses ParseQuery to check for malform paramater value pairs.
Runs ./mvnw clean package, ./bin/generate-samples.sh ./bin/configs/*.yaml, and ./bin/utils/export_docs_generators.sh.

* Adds missing import

* Only import url if hasQueryParams.

* Adds helper function to wrap url.ParseQuery.

* Fixes function return signature
This commit is contained in:
Gonzalo Gomez
2024-01-14 22:43:04 -07:00
committed by GitHub
parent 6518932ccf
commit af71460c86
11 changed files with 123 additions and 19 deletions

View File

@@ -173,7 +173,11 @@ func (c *UserAPIController) CreateUsersWithListInput(w http.ResponseWriter, r *h
// DeleteUser - Delete user
func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
query := r.URL.Query()
query, err := parseQuery(r.URL.RawQuery)
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
usernameParam := params["username"]
if usernameParam == "" {
c.errorHandler(w, r, &RequiredError{"username"}, nil)
@@ -223,7 +227,11 @@ func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request
// LoginUser - Logs user into the system
func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
query, err := parseQuery(r.URL.RawQuery)
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
var usernameParam string
if query.Has("username") {
param := query.Get("username")