Skip to content

Commit

Permalink
Merge pull request #18 from mattkasun/master
Browse files Browse the repository at this point in the history
remove erroneous extra blank line during parse
  • Loading branch information
cjimti committed Feb 11, 2023
2 parents b4a4cf7 + 4d96640 commit 8a33103
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions txeh.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ func ParseHosts(path string) ([]HostFileLine, error) {
inputNormalized := strings.Replace(string(input), "\r\n", "\n", -1)

dataLines := strings.Split(inputNormalized, "\n")
//remove extra blank line at end that does not exist in /etc/hosts file
dataLines = dataLines[:len(dataLines)-1]

hostFileLines := make([]HostFileLine, len(dataLines))

Expand Down Expand Up @@ -377,9 +379,12 @@ func lineFormatter(hfl HostFileLine) string {
}
return fmt.Sprintf("%-16s %s", hfl.Address, strings.Join(hfl.Hostnames, " "))
}

// IPLocalhost is a regex pattern for IPv4 or IPv6 loopback range.
const ipLocalhost = `((127\.([0-9]{1,3}\.){2}[0-9]{1,3})|(::1)$)`

var localhostIPRegexp = regexp.MustCompile(ipLocalhost)

func isLocalhost(address string) bool {
return localhostIPRegexp.MatchString(address)
}

0 comments on commit 8a33103

Please sign in to comment.