pkg: use {strings,bytes}.ReplaceAll when possible (#320)

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 <miguelangel4b@gmail.com>
This commit is contained in:
M. Ángel Jimeno 2020-10-02 16:12:40 +02:00 committed by GitHub
parent 6bf3542332
commit 8156fd1917
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View file

@ -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 {

View file

@ -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