resolv.conf comments have '#' or ';' in the first column
When a '#' or ';' appears anywhere else, it's not a comment marker. Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
parent
137a9d6a4c
commit
7f69142aa0
2 changed files with 23 additions and 26 deletions
|
@ -452,18 +452,8 @@ func UserModified(rcPath, rcHashPath string) (bool, error) {
|
|||
func (rc *ResolvConf) processLine(line string) {
|
||||
fields := strings.Fields(line)
|
||||
|
||||
// Strip comments.
|
||||
// TODO(robmry) - ignore comment chars except in column 0.
|
||||
// This preserves old behaviour, but it's wrong. For example, resolvers
|
||||
// will honour the option in line "options # ndots:0" (and ignore the
|
||||
// "#" as an unknown option).
|
||||
for i, s := range fields {
|
||||
if s[0] == '#' || s[0] == ';' {
|
||||
fields = fields[:i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(fields) == 0 {
|
||||
// Strip blank lines and comments.
|
||||
if len(fields) == 0 || fields[0][0] == '#' || fields[0][0] == ';' {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -149,16 +149,16 @@ func TestGetSearchDomains(t *testing.T) {
|
|||
result: []string{"example.com"},
|
||||
},
|
||||
{
|
||||
input: `search example.com # ignored`,
|
||||
result: []string{"example.com"},
|
||||
input: `search example.com # notignored`,
|
||||
result: []string{"example.com", "#", "notignored"},
|
||||
},
|
||||
{
|
||||
input: ` search example.com `,
|
||||
result: []string{"example.com"},
|
||||
},
|
||||
{
|
||||
input: ` search example.com # ignored`,
|
||||
result: []string{"example.com"},
|
||||
input: ` search example.com # notignored`,
|
||||
result: []string{"example.com", "#", "notignored"},
|
||||
},
|
||||
{
|
||||
input: `search foo.example.com example.com`,
|
||||
|
@ -169,8 +169,8 @@ func TestGetSearchDomains(t *testing.T) {
|
|||
result: []string{"foo.example.com", "example.com"},
|
||||
},
|
||||
{
|
||||
input: ` search foo.example.com example.com # ignored`,
|
||||
result: []string{"foo.example.com", "example.com"},
|
||||
input: ` search foo.example.com example.com # notignored`,
|
||||
result: []string{"foo.example.com", "example.com", "#", "notignored"},
|
||||
},
|
||||
{
|
||||
input: `nameserver 1.2.3.4
|
||||
|
@ -212,6 +212,9 @@ func TestGetOptions(t *testing.T) {
|
|||
{
|
||||
input: `# ignored`,
|
||||
},
|
||||
{
|
||||
input: `; ignored`,
|
||||
},
|
||||
{
|
||||
input: `nameserver 1.2.3.4`,
|
||||
},
|
||||
|
@ -220,32 +223,36 @@ func TestGetOptions(t *testing.T) {
|
|||
result: []string{"opt1"},
|
||||
},
|
||||
{
|
||||
input: `options opt1 # ignored`,
|
||||
result: []string{"opt1"},
|
||||
input: `options opt1 # notignored`,
|
||||
result: []string{"opt1", "#", "notignored"},
|
||||
},
|
||||
{
|
||||
input: `options opt1 ; notignored`,
|
||||
result: []string{"opt1", ";", "notignored"},
|
||||
},
|
||||
{
|
||||
input: ` options opt1 `,
|
||||
result: []string{"opt1"},
|
||||
},
|
||||
{
|
||||
input: ` options opt1 # ignored`,
|
||||
result: []string{"opt1"},
|
||||
input: ` options opt1 # notignored`,
|
||||
result: []string{"opt1", "#", "notignored"},
|
||||
},
|
||||
{
|
||||
input: `options opt1 opt2 opt3`,
|
||||
result: []string{"opt1", "opt2", "opt3"},
|
||||
},
|
||||
{
|
||||
input: `options opt1 opt2 opt3 # ignored`,
|
||||
result: []string{"opt1", "opt2", "opt3"},
|
||||
input: `options opt1 opt2 opt3 # notignored`,
|
||||
result: []string{"opt1", "opt2", "opt3", "#", "notignored"},
|
||||
},
|
||||
{
|
||||
input: ` options opt1 opt2 opt3 `,
|
||||
result: []string{"opt1", "opt2", "opt3"},
|
||||
},
|
||||
{
|
||||
input: ` options opt1 opt2 opt3 # ignored`,
|
||||
result: []string{"opt1", "opt2", "opt3"},
|
||||
input: ` options opt1 opt2 opt3 # notignored`,
|
||||
result: []string{"opt1", "opt2", "opt3", "#", "notignored"},
|
||||
},
|
||||
{
|
||||
input: `nameserver 1.2.3.4
|
||||
|
|
Loading…
Reference in a new issue