Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
szolin committed Jun 17, 2020
1 parent 9b8c710 commit 9d3e280
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion util/auto_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,21 @@ func (a *AutoHosts) load(table map[string][]net.IP, tableRev map[string]string,
}
for i := 1; i != len(fields); i++ {
host := fields[i]
if len(host) == 0 || host[0] == '#' {
if len(host) == 0 {
break
}
sharp := strings.IndexByte(host, '#')
if sharp == 0 {
break // skip the rest of the line after #
} else if sharp > 0 {
host = host[:sharp]
}

a.updateTable(table, host, ipAddr)
a.updateTableRev(tableRev, host, ipAddr)
if sharp >= 0 {
break // skip the rest of the line after #
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion util/auto_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAutoHostsResolution(t *testing.T) {
defer f.Close()

_, _ = f.WriteString(" 127.0.0.1 host localhost # comment \n")
_, _ = f.WriteString(" ::1 localhost \n")
_, _ = f.WriteString(" ::1 localhost#comment \n")

ah.Init(f.Name())

Expand Down

0 comments on commit 9d3e280

Please sign in to comment.