Fix parsing blank lines

pull/13/head
Chris Bednarski 9 years ago
parent 546a3f9c37
commit b52b8571fd

@ -1,7 +1,7 @@
package main
import (
// "fmt"
"fmt"
"github.com/cbednarski/hostess"
"os"
)
@ -18,4 +18,5 @@ func main() {
hostfile := hostess.NewHostfile(hostess.GetHostsPath())
hostfile.Load()
hostfile.Parse()
fmt.Println(hostfile)
}

@ -59,6 +59,10 @@ func LooksLikeIpv6(ip string) bool {
func parseLine(line string) []Hostname {
var hostnames []Hostname
if len(line) == 0 {
return hostnames
}
// Parse leading # for disabled lines
enabled := true
if line[0:1] == "#" {

@ -174,6 +174,12 @@ func TestListDomainsByIp(t *testing.T) {
func TestParseLine(t *testing.T) {
var hosts = []Hostname{}
// Blank line
hosts = parseLine("")
if len(hosts) > 0 {
t.Error("Expected to find zero hostnames")
}
// Comment
hosts = parseLine("# The following lines are desirable for IPv6 capable hosts")
if len(hosts) > 0 {

Loading…
Cancel
Save