handle null bytes

This commit is contained in:
Karl Seguin 2014-12-23 23:10:36 +07:00
parent 3c61b16776
commit 43e06f9c62
2 changed files with 19 additions and 0 deletions

View File

@ -191,6 +191,10 @@ func (r *msgReader) readBytes(count int32) []byte {
return nil
}
if count < 1 {
return nil
}
b := make([]byte, int(count))
_, err := io.ReadFull(r.reader, b)

View File

@ -806,3 +806,18 @@ func TestReadingValueAfterEmptyArray(t *testing.T) {
t.Errorf("Expected 'b' to 42, but it was: ", b)
}
}
func TestReadingNullByteArray(t *testing.T) {
conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn)
var a []byte
err := conn.QueryRow("select null::text").Scan(&a)
if err != nil {
t.Fatalf("conn.QueryRow failed: ", err)
}
if len(a) != 0 {
t.Errorf("Expected 'a' to have length 0, but it was: ", len(a))
}
}