remove trailing dots from the parsed searches from host resolv.conf

This commit is contained in:
Fernando Crespo Gravalos 2019-09-24 16:30:22 +02:00 committed by Fernando Crespo Grávalos
parent 0541d0bb79
commit a215a88d91
2 changed files with 6 additions and 1 deletions

View File

@ -230,7 +230,11 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
}
}
if fields[0] == "search" {
searches = fields[1:]
trimTrailingDot := []string{}
for _, s := range fields[1:] {
trimTrailingDot = append(trimTrailingDot, strings.TrimSuffix(s, "."))
}
searches = trimTrailingDot
}
if fields[0] == "options" {
options = fields[1:]

View File

@ -74,6 +74,7 @@ func TestParseResolvConf(t *testing.T) {
{"search ", []string{}, []string{}, []string{}, false}, // search empty
{"search foo", []string{}, []string{"foo"}, []string{}, false},
{"search foo bar", []string{}, []string{"foo", "bar"}, []string{}, false},
{"search foo. bar", []string{}, []string{"foo", "bar"}, []string{}, false},
{"search foo bar bat\n", []string{}, []string{"foo", "bar", "bat"}, []string{}, false},
{"search foo\nsearch bar", []string{}, []string{"bar"}, []string{}, false},
{"nameserver 1.2.3.4\nsearch foo bar", []string{"1.2.3.4"}, []string{"foo", "bar"}, []string{}, false},