Merge pull request #83069 from fcgravalos/remove_trailing_dots_from_searches

remove trailing dots from the parsed searches from host resolv.conf
This commit is contained in:
Kubernetes Prow Robot 2019-10-07 11:27:11 -07:00 committed by GitHub
commit 39ba488be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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:]
// Normalise search fields so the same domain with and without trailing dot will only count once, to avoid hitting search validation limits.
searches = []string{}
for _, s := range fields[1:] {
searches = append(searches, strings.TrimSuffix(s, "."))
}
}
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},