Avoid strings.ReplaceAll() that was introduced too recently

This commit is contained in:
Frank Denis 2019-10-12 22:22:28 +02:00
parent ed0dbc2b55
commit 63e6dbdac7
2 changed files with 10 additions and 1 deletions

View File

@ -134,6 +134,15 @@ func StringQuote(str string) string {
return str[1 : len(str)-1]
}
func StringStripSpaces(str string) string {
return strings.Map(func(r rune) rune {
if unicode.IsSpace(r) {
return -1
}
return r
}, str)
}
func ExtractPort(str string, defaultPort int) int {
port := defaultPort
if idx := strings.LastIndex(str, ":"); idx >= 0 && idx < len(str)-1 {

View File

@ -154,7 +154,7 @@ func InitPluginsGlobals(pluginsGlobals *PluginsGlobals, proxy *Proxy) error {
// blockedQueryResponse can be 'refused', 'hinfo' or IP responses 'a:IPv4,aaaa:IPv6
func parseBlockedQueryResponse(blockedResponse string, pluginsGlobals *PluginsGlobals) {
blockedResponse = strings.ReplaceAll(strings.ToLower(blockedResponse), " ", "")
blockedResponse = StringStripSpaces(strings.ToLower(blockedResponse))
if strings.HasPrefix(blockedResponse, "a:") {
blockedIPStrings := strings.Split(blockedResponse, ",")