From 2527a351b8f1c84e78914fb854143dd54ee3828b Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Thu, 12 Jan 2023 12:11:58 +0100 Subject: [PATCH] Trim spaces from search-query strings and tags - Relates to issue #78 --- cmd/cc-backend/main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/cc-backend/main.go b/cmd/cc-backend/main.go index f52f8a3..0556cc7 100644 --- a/cmd/cc-backend/main.go +++ b/cmd/cc-backend/main.go @@ -301,15 +301,15 @@ func main() { splitSearch := strings.Split(search, ":") if (len(splitSearch) == 2) { - switch splitSearch[0] { + switch strings.Trim(splitSearch[0], " ") { case "jobId": - http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(splitSearch[1]), http.StatusTemporaryRedirect) // All Users: Redirect to Tablequery + http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(strings.Trim(splitSearch[1], " ")), http.StatusTemporaryRedirect) // All Users: Redirect to Tablequery return case "jobName": - http.Redirect(rw, r, "/monitoring/jobs/?jobName="+url.QueryEscape(splitSearch[1]), http.StatusTemporaryRedirect) // All Users: Redirect to Tablequery + http.Redirect(rw, r, "/monitoring/jobs/?jobName="+url.QueryEscape(strings.Trim(splitSearch[1], " ")), http.StatusTemporaryRedirect) // All Users: Redirect to Tablequery return case "projectId": - project, _ := api.JobRepository.FindProject(r.Context(), splitSearch[1]) // Restricted: projectId + project, _ := api.JobRepository.FindProject(r.Context(), strings.Trim(splitSearch[1], " ")) // Restricted: projectId if project != "" { http.Redirect(rw, r, "/monitoring/jobs/?projectMatch=eq&project="+url.QueryEscape(project), http.StatusTemporaryRedirect) return @@ -317,7 +317,7 @@ func main() { http.Redirect(rw, r, "/monitoring/jobs/?jobId=NotFound", http.StatusTemporaryRedirect) // Workaround to display correctly empty table } case "username": - username, _ := api.JobRepository.FindUser(r.Context(), splitSearch[1]) // Restricted: username + username, _ := api.JobRepository.FindUser(r.Context(), strings.Trim(splitSearch[1], " ")) // Restricted: username if username != "" { http.Redirect(rw, r, "/monitoring/user/"+username, http.StatusTemporaryRedirect) return @@ -329,7 +329,7 @@ func main() { } } else if (len(splitSearch) == 1) { - jobname, username, project, err := api.JobRepository.FindJobnameOrUserOrProject(r.Context(), search) // Determine Access within + jobname, username, project, err := api.JobRepository.FindJobnameOrUserOrProject(r.Context(), strings.Trim(search, " ")) // Determine Access within if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) @@ -340,13 +340,13 @@ func main() { http.Redirect(rw, r, "/monitoring/user/"+username, http.StatusTemporaryRedirect) // User: Redirect to user page return } else if (project != "") { - http.Redirect(rw, r, "/monitoring/jobs/?projectMatch=eq&project="+url.QueryEscape(search), http.StatusTemporaryRedirect) // projectId (equal) + http.Redirect(rw, r, "/monitoring/jobs/?projectMatch=eq&project="+url.QueryEscape(strings.Trim(search, " ")), http.StatusTemporaryRedirect) // projectId (equal) return } else if (jobname != "") { - http.Redirect(rw, r, "/monitoring/jobs/?jobName="+url.QueryEscape(search), http.StatusTemporaryRedirect) // JobName (contains) + http.Redirect(rw, r, "/monitoring/jobs/?jobName="+url.QueryEscape(strings.Trim(search, " ")), http.StatusTemporaryRedirect) // JobName (contains) return } else { - http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(search), http.StatusTemporaryRedirect) // No Result: Probably jobId + http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(strings.Trim(search, " ")), http.StatusTemporaryRedirect) // No Result: Probably jobId return }