From 3294a8cf1f2701b7bcc229597e7e4081b5d49532 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 20 May 2019 16:26:58 -0500 Subject: [PATCH] Allow empty hstore keys See pgx commit: 56f4f0b9d319a910016ce044a53f52fcf986ddc6 --- hstore.go | 10 +++------- hstore_test.go | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/hstore.go b/hstore.go index 522813ff..56af38ee 100644 --- a/hstore.go +++ b/hstore.go @@ -297,13 +297,9 @@ func parseHstore(s string) (k []string, v []Text, err error) { case hsKey: switch r { case '"': //End of the key - if buf.Len() == 0 { - err = errors.New("Empty Key is invalid") - } else { - keys = append(keys, buf.String()) - buf = bytes.Buffer{} - state = hsSep - } + keys = append(keys, buf.String()) + buf = bytes.Buffer{} + state = hsSep case '\\': //Potential escaped character n, end := p.Consume() switch { diff --git a/hstore_test.go b/hstore_test.go index ccd476dc..ba6c9373 100644 --- a/hstore_test.go +++ b/hstore_test.go @@ -19,6 +19,7 @@ func TestHstoreTranscode(t *testing.T) { &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}, &pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("NULL")}, Status: pgtype.Present}, + &pgtype.Hstore{Map: map[string]pgtype.Text{"": text("bar")}, Status: pgtype.Present}, &pgtype.Hstore{Status: pgtype.Null}, }