]> Cypherpunks repositories - gostls13.git/commitdiff
net: handle single-line non-\n-terminated files correctly in readLine
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 28 Oct 2013 23:31:25 +0000 (19:31 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 28 Oct 2013 23:31:25 +0000 (19:31 -0400)
Fixes #6646.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/15960047

src/pkg/net/hosts_test.go
src/pkg/net/parse.go
src/pkg/net/testdata/hosts_singleline [new file with mode: 0644]

index 064e7e432827f0c5c0c80ca9ed54cf736acc8c02..b07ed0baa942df8444ea668275a2354f2797c4fe 100644 (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
index 7c87b42f6d9edbc3ddef05a105d282e7f724a9e1..6056de248e052e39bf0ebed84269a5dcd21ec420 100644 (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
                }
        }
diff --git a/src/pkg/net/testdata/hosts_singleline b/src/pkg/net/testdata/hosts_singleline
new file mode 100644 (file)
index 0000000..5f5f74a
--- /dev/null
@@ -0,0 +1 @@
+127.0.0.2      odin
\ No newline at end of file