mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 18:55:24 +00:00
* Replacing regex with lexical analyzer taken from 610beb8534/v2/pkg/protocols/common/expressions/expressions.go (L66)
34 lines
998 B
Go
34 lines
998 B
Go
package replacer
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/marker"
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
|
)
|
|
|
|
// Replace replaces placeholders in template with values on the fly.
|
|
func Replace(template string, values map[string]interface{}) string {
|
|
var replacerItems []string
|
|
|
|
builder := &strings.Builder{}
|
|
for key, val := range values {
|
|
builder.WriteString(marker.ParenthesisOpen)
|
|
builder.WriteString(key)
|
|
builder.WriteString(marker.ParenthesisClose)
|
|
replacerItems = append(replacerItems, builder.String())
|
|
builder.Reset()
|
|
replacerItems = append(replacerItems, types.ToString(val))
|
|
|
|
builder.WriteString(marker.General)
|
|
builder.WriteString(key)
|
|
builder.WriteString(marker.General)
|
|
replacerItems = append(replacerItems, builder.String())
|
|
builder.Reset()
|
|
replacerItems = append(replacerItems, types.ToString(val))
|
|
}
|
|
replacer := strings.NewReplacer(replacerItems...)
|
|
final := replacer.Replace(template)
|
|
return final
|
|
}
|