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:
parent
6bf3542332
commit
8156fd1917
@ -41,7 +41,7 @@ func (f *RegexpFilter) Filter(response *ffuf.Response) (bool, error) {
|
|||||||
matchdata = append(matchdata, response.Data...)
|
matchdata = append(matchdata, response.Data...)
|
||||||
pattern := f.valueRaw
|
pattern := f.valueRaw
|
||||||
for keyword, inputitem := range response.Request.Input {
|
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)
|
matched, err := regexp.Match(pattern, matchdata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -77,15 +77,15 @@ func (r *SimpleRunner) Prepare(input map[string][]byte) (ffuf.Request, error) {
|
|||||||
req.Data = []byte(r.config.Data)
|
req.Data = []byte(r.config.Data)
|
||||||
|
|
||||||
for keyword, inputitem := range input {
|
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)
|
headers := make(map[string]string, 0)
|
||||||
for h, v := range req.Headers {
|
for h, v := range req.Headers {
|
||||||
var CanonicalHeader string = textproto.CanonicalMIMEHeaderKey(strings.Replace(h, keyword, string(inputitem), -1))
|
var CanonicalHeader string = textproto.CanonicalMIMEHeaderKey(strings.ReplaceAll(h, keyword, string(inputitem)))
|
||||||
headers[CanonicalHeader] = strings.Replace(v, keyword, string(inputitem), -1)
|
headers[CanonicalHeader] = strings.ReplaceAll(v, keyword, string(inputitem))
|
||||||
}
|
}
|
||||||
req.Headers = headers
|
req.Headers = headers
|
||||||
req.Url = strings.Replace(req.Url, keyword, string(inputitem), -1)
|
req.Url = strings.ReplaceAll(req.Url, keyword, string(inputitem))
|
||||||
req.Data = []byte(strings.Replace(string(req.Data), keyword, string(inputitem), -1))
|
req.Data = []byte(strings.ReplaceAll(string(req.Data), keyword, string(inputitem)))
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Input = input
|
req.Input = input
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user