1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:00:22 -07:00

net: handle single-line non-\n-terminated files correctly in readLine

Fixes #6646.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/15960047
This commit is contained in:
Josh Bleecher Snyder 2013-10-28 19:31:25 -04:00 committed by Russ Cox
parent 6ea5687b46
commit 5644774ea5
3 changed files with 15 additions and 1 deletions

View File

@ -53,6 +53,19 @@ func TestLookupStaticHost(t *testing.T) {
hostsPath = p
}
// https://code.google.com/p/go/issues/detail?id=6646
func TestSingleLineHostsFile(t *testing.T) {
p := hostsPath
hostsPath = "testdata/hosts_singleline"
ips := lookupStaticHost("odin")
if len(ips) != 1 || ips[0] != "127.0.0.2" {
t.Errorf("lookupStaticHost = %v, want %v", ips, []string{"127.0.0.2"})
}
hostsPath = p
}
func TestLookupHost(t *testing.T) {
// Can't depend on this to return anything in particular,
// but if it does return something, make sure it doesn't

View File

@ -54,7 +54,7 @@ func (f *file) readLine() (s string, ok bool) {
if n >= 0 {
f.data = f.data[0 : ln+n]
}
if err == io.EOF {
if err == io.EOF || err == io.ErrUnexpectedEOF {
f.atEOF = true
}
}

1
src/pkg/net/testdata/hosts_singleline vendored Normal file
View File

@ -0,0 +1 @@
127.0.0.2 odin