Skip to content

Commit

Permalink
fix panic on json.RawMessage parse
Browse files Browse the repository at this point in the history
  • Loading branch information
xiam committed Jul 4, 2022
1 parent 2147806 commit 8292c3e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions adapter/postgresql/helper_test.go
Expand Up @@ -194,6 +194,7 @@ func (h *Helper) TearUp() error {
, integer_array integer[]
, string_array text[]
, jsonb_map jsonb
, raw_jsonb_map jsonb
, integer_array_ptr integer[]
, string_array_ptr text[]
Expand Down
6 changes: 6 additions & 0 deletions adapter/postgresql/postgresql_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
"math/rand"
"strings"
Expand Down Expand Up @@ -229,6 +230,8 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) {
StringArray StringArray `db:"string_array,stringarray"`
JSONBMap JSONBMap `db:"jsonb_map"`

RawJSONBMap json.RawMessage `db:"raw_jsonb_map"`

PGTypeInline `db:",inline"`

PGTypeAutoInline `db:",inline"`
Expand Down Expand Up @@ -329,6 +332,9 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) {
AutoJSONBMapInteger: map[string]interface{}{"a": 12.0, "b": 13.0},
},
},
PGType{
RawJSONBMap: json.RawMessage(`{"foo": "bar"}`),
},
PGType{
IntegerValue: integerValue,
StringValue: stringValue,
Expand Down
2 changes: 1 addition & 1 deletion internal/sqlbuilder/convert.go
Expand Up @@ -57,7 +57,7 @@ func toInterfaceArguments(value interface{}) (args []interface{}, isSlice bool)

// Byte slice gets transformed into a string.
if v.Type().Elem().Kind() == reflect.Uint8 {
return []interface{}{string(value.([]byte))}, false
return []interface{}{string(v.Bytes())}, false
}

total = v.Len()
Expand Down

0 comments on commit 8292c3e

Please sign in to comment.