From 36944b232f3846ddeb8ad110df5aa266639f3469 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Jun 2020 10:26:34 -0500 Subject: [PATCH] Fix hstore with empty string values --- hstore.go | 3 ++- hstore_test.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hstore.go b/hstore.go index 3fe50ae5..ec510df7 100644 --- a/hstore.go +++ b/hstore.go @@ -168,6 +168,7 @@ func (src Hstore) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { firstPair := true + inElemBuf := make([]byte, 0, 32) for k, v := range src.Map { if firstPair { firstPair = false @@ -178,7 +179,7 @@ func (src Hstore) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { buf = append(buf, quoteHstoreElementIfNeeded(k)...) buf = append(buf, "=>"...) - elemBuf, err := v.EncodeText(ci, nil) + elemBuf, err := v.EncodeText(ci, inElemBuf) if err != nil { return nil, err } diff --git a/hstore_test.go b/hstore_test.go index ba6c9373..dce8baf2 100644 --- a/hstore_test.go +++ b/hstore_test.go @@ -15,6 +15,7 @@ func TestHstoreTranscode(t *testing.T) { values := []interface{}{ &pgtype.Hstore{Map: map[string]pgtype.Text{}, Status: pgtype.Present}, + &pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text(""), "bar": text(""), "baz": text("123")}, Status: pgtype.Present}, &pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar")}, Status: pgtype.Present}, &pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar"), "baz": text("quz")}, Status: pgtype.Present}, &pgtype.Hstore{Map: map[string]pgtype.Text{"NULL": text("bar")}, Status: pgtype.Present},