Chore: Use strings.ReplaceAll and preallocate containers (#58483)

This commit is contained in:
Sasha Melentyev
2022-11-09 17:17:09 +01:00
committed by GitHub
parent 2dfe0a4060
commit febcaeff3a
6 changed files with 10 additions and 10 deletions
@@ -14,7 +14,7 @@ func hello(w http.ResponseWriter, r *http.Request) {
return
}
safeBody := strings.Replace(string(body), "\n", "", -1)
safeBody := strings.ReplaceAll(string(body), "\n", "")
line := fmt.Sprintf("webbhook: -> %s", safeBody)
fmt.Println(line)
if _, err := io.WriteString(w, line); err != nil {
+2 -2
View File
@@ -32,8 +32,8 @@ func main() {
proxy := httputil.NewSingleHostReverseProxy(originURL)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
safeSleep := strings.Replace(sleep.String(), "\n", "", -1)
safeRequestUri := strings.Replace(r.RequestURI, "\n", "", -1)
safeSleep := strings.ReplaceAll(sleep.String(), "\n", "")
safeRequestUri := strings.ReplaceAll(r.RequestURI, "\n", "")
log.Printf("sleeping for %s then proxying request: url '%s'", safeSleep, safeRequestUri)
// This is commented out as CodeQL flags this as vulnerability CWE-117 (https://cwe.mitre.org/data/definitions/117.html)