Fix hstore binary null decoding

Bug was advancing the read pointer by the length of the value even if it
was a NULL value. Since NULL is indicated by a -1 length it actually
decremented the read pointer.
non-blocking
Jack Christensen 2021-07-31 11:06:03 -05:00
parent e26c6b4e3d
commit 6bda09691d
2 changed files with 5 additions and 1 deletions

View File

@ -142,8 +142,8 @@ func (dst *Hstore) DecodeBinary(ci *ConnInfo, src []byte) error {
var valueBuf []byte
if valueLen >= 0 {
valueBuf = src[rp : rp+valueLen]
rp += valueLen
}
rp += valueLen
var value Text
err := value.DecodeBinary(ci, valueBuf)

View File

@ -21,6 +21,10 @@ func TestHstoreTranscode(t *testing.T) {
&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{
Map: map[string]pgtype.Text{"a": text("a"), "b": {Status: pgtype.Null}, "c": text("c"), "d": {Status: pgtype.Null}, "e": text("e")},
Status: pgtype.Present,
},
&pgtype.Hstore{Status: pgtype.Null},
}