Skip to content

Commit 6a6ff19

Browse files
committed
veqryn/marshal-json: convert json into strings
1 parent d8cca0e commit 6a6ff19

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

v2/metadata.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bugsnag
22

33
import (
44
"encoding"
5+
"encoding/json"
56
"fmt"
67
"reflect"
78
"strings"
@@ -114,6 +115,11 @@ func (s sanitizer) Sanitize(data interface{}) interface{} {
114115
if b, err := dataT.MarshalText(); err == nil {
115116
return string(b)
116117
}
118+
119+
case json.Marshaler:
120+
if b, err := dataT.MarshalJSON(); err == nil {
121+
return string(b)
122+
}
117123
}
118124

119125
switch t.Kind() {

v2/metadata_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bugsnag
22

33
import (
4+
"encoding/json"
45
stderrors "errors"
56
"reflect"
67
"testing"
@@ -215,6 +216,7 @@ func TestMetaDataSanitize(t *testing.T) {
215216
"time": time.Date(2023, 12, 5, 23, 59, 59, 123456789, time.UTC),
216217
"duration": 105567462 * time.Millisecond,
217218
"text": _textMarshaller{},
219+
"json": json.RawMessage(`{"hello": "world"}`),
218220
"array": []hash{{
219221
"creditcard": "1234567812345678",
220222
"broken": broken,
@@ -240,6 +242,7 @@ func TestMetaDataSanitize(t *testing.T) {
240242
"time": "2023-12-05T23:59:59.123456789Z",
241243
"duration": "29h19m27.462s",
242244
"text": "marshalled text",
245+
"json": `{"hello": "world"}`,
243246
"array": []interface{}{map[string]interface{}{
244247
"creditcard": "[FILTERED]",
245248
"broken": map[string]interface{}{

0 commit comments

Comments
 (0)