From 8156fd1917a648d3faa809b29f2cab68b9076454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20=C3=81ngel=20Jimeno?= Date: Fri, 2 Oct 2020 16:12:40 +0200 Subject: [PATCH] pkg: use {strings,bytes}.ReplaceAll when possible (#320) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the ReplaceAll helper from the standard library in order to make the code easier to read. Requires Go 1.12 or higher. Fixes #301 Signed-off-by: Miguel Ángel Jimeno --- pkg/filter/regex.go | 2 +- pkg/runner/simple.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/filter/regex.go b/pkg/filter/regex.go index 6c47110..57291e1 100644 --- a/pkg/filter/regex.go +++ b/pkg/filter/regex.go @@ -41,7 +41,7 @@ func (f *RegexpFilter) Filter(response *ffuf.Response) (bool, error) { matchdata = append(matchdata, response.Data...) pattern := f.valueRaw for keyword, inputitem := range response.Request.Input { - pattern = strings.Replace(pattern, keyword, regexp.QuoteMeta(string(inputitem)), -1) + pattern = strings.ReplaceAll(pattern, keyword, regexp.QuoteMeta(string(inputitem))) } matched, err := regexp.Match(pattern, matchdata) if err != nil { diff --git a/pkg/runner/simple.go b/pkg/runner/simple.go index 3b7cbd9..8af2886 100644 --- a/pkg/runner/simple.go +++ b/pkg/runner/simple.go @@ -77,15 +77,15 @@ func (r *SimpleRunner) Prepare(input map[string][]byte) (ffuf.Request, error) { req.Data = []byte(r.config.Data) for keyword, inputitem := range input { - req.Method = strings.Replace(req.Method, keyword, string(inputitem), -1) + req.Method = strings.ReplaceAll(req.Method, keyword, string(inputitem)) headers := make(map[string]string, 0) for h, v := range req.Headers { - var CanonicalHeader string = textproto.CanonicalMIMEHeaderKey(strings.Replace(h, keyword, string(inputitem), -1)) - headers[CanonicalHeader] = strings.Replace(v, keyword, string(inputitem), -1) + var CanonicalHeader string = textproto.CanonicalMIMEHeaderKey(strings.ReplaceAll(h, keyword, string(inputitem))) + headers[CanonicalHeader] = strings.ReplaceAll(v, keyword, string(inputitem)) } req.Headers = headers - req.Url = strings.Replace(req.Url, keyword, string(inputitem), -1) - req.Data = []byte(strings.Replace(string(req.Data), keyword, string(inputitem), -1)) + req.Url = strings.ReplaceAll(req.Url, keyword, string(inputitem)) + req.Data = []byte(strings.ReplaceAll(string(req.Data), keyword, string(inputitem))) } req.Input = input