From 104c01df218e7a68cb25e5a87ddbd08942f3082d Mon Sep 17 00:00:00 2001 From: Manni Wood Date: Sat, 12 Nov 2016 12:28:31 -0500 Subject: [PATCH] Handles aclitem lists of 1+ --- values.go | 20 +++++++++++++++++--- values_test.go | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/values.go b/values.go index e0d56351..395b59ce 100644 --- a/values.go +++ b/values.go @@ -3000,8 +3000,15 @@ func decodeTextArray(vr *ValueReader) []string { } // XXX: encodeAclItemSlice; using text encoding, not binary -func encodeAclItemSlice(w *WriteBuf, oid Oid, value []AclItem) error { - str := "{" + value[0] + "}" +func encodeAclItemSlice(w *WriteBuf, oid Oid, aclitems []AclItem) error { + // cast aclitems into strings so we can use strings.Join + strs := make([]string, len(aclitems)) + for i := range strs { + strs[i] = string(aclitems[i]) + } + + str := strings.Join(strs, ",") + str = "{" + str + "}" w.WriteInt32(int32(len(str))) w.WriteBytes([]byte(str)) return nil @@ -3017,7 +3024,14 @@ func decodeAclItemArray(vr *ValueReader) []AclItem { str := vr.ReadString(vr.Len()) // remove the '{' at the front and the '}' at the end str = str[1 : len(str)-1] - return []AclItem{AclItem(str)} + strs := strings.Split(str, ",") + + // cast strings into AclItems before returning + aclitems := make([]AclItem, len(strs)) + for i := range aclitems { + aclitems[i] = AclItem(strs[i]) + } + return aclitems } func encodeStringSlice(w *WriteBuf, oid Oid, slice []string) error { diff --git a/values_test.go b/values_test.go index 46652d4d..83244b1b 100644 --- a/values_test.go +++ b/values_test.go @@ -665,6 +665,10 @@ func TestAclArrayDecoding(t *testing.T) { []pgx.AclItem{"=r/postgres"}, &[]pgx.AclItem{}, }, + { + []pgx.AclItem{"=r/postgres", "postgres=arwdDxt/postgres"}, + &[]pgx.AclItem{}, + }, } for i, tt := range tests { err := conn.QueryRow(sql, tt.query).Scan(tt.scan)