aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2013-11-01 11:21:05 +1100
committerRuss Cox <rsc@golang.org>2013-11-01 11:21:05 +1100
commit724d28a03d24aa404b7a6e83972e52b6732bbe17 (patch)
tree1ff22a39fc75dbe3a7dc95efe718f5d3d0d44c9f
parent7097ed7337135c68b3c721a4963ef936e003e487 (diff)
downloadgo-724d28a03d24aa404b7a6e83972e52b6732bbe17.tar.gz
go-724d28a03d24aa404b7a6e83972e52b6732bbe17.zip
[release-branch.go1.2] net: handle single-line non-\n-terminated files correctly in readLine
««« CL 15960047 / a0d4544cdb2a net: handle single-line non-\n-terminated files correctly in readLine Fixes #6646. R=rsc, bradfitz CC=golang-dev https://golang.org/cl/15960047 »»» R=golang-dev CC=golang-dev https://golang.org/cl/20560044
-rw-r--r--src/pkg/net/hosts_test.go13
-rw-r--r--src/pkg/net/parse.go2
-rw-r--r--src/pkg/net/testdata/hosts_singleline1
3 files changed, 15 insertions, 1 deletions
diff --git a/src/pkg/net/hosts_test.go b/src/pkg/net/hosts_test.go
index 064e7e4328..b07ed0baa9 100644
--- a/src/pkg/net/hosts_test.go
+++ b/src/pkg/net/hosts_test.go
@@ -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
diff --git a/src/pkg/net/parse.go b/src/pkg/net/parse.go
index 7c87b42f6d..6056de248e 100644
--- a/src/pkg/net/parse.go
+++ b/src/pkg/net/parse.go
@@ -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
}
}
diff --git a/src/pkg/net/testdata/hosts_singleline b/src/pkg/net/testdata/hosts_singleline
new file mode 100644
index 0000000000..5f5f74a3fa
--- /dev/null
+++ b/src/pkg/net/testdata/hosts_singleline
@@ -0,0 +1 @@
+127.0.0.2 odin \ No newline at end of file