Skip to content

Commit

Permalink
veqryn/marshal-json: convert json into strings
Browse files Browse the repository at this point in the history
  • Loading branch information
veqryn committed Apr 9, 2024
1 parent c17eb96 commit 2fa53ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions v2/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bugsnag

import (
"encoding"
"encoding/json"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -114,6 +115,11 @@ func (s sanitizer) Sanitize(data interface{}) interface{} {
if b, err := dataT.MarshalText(); err == nil {
return string(b)
}

case json.Marshaler:
if b, err := dataT.MarshalJSON(); err == nil {
return string(b)
}
}

switch t.Kind() {
Expand Down
3 changes: 3 additions & 0 deletions v2/metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bugsnag

import (
"encoding/json"
stderrors "errors"
"reflect"
"testing"
Expand Down Expand Up @@ -215,6 +216,7 @@ func TestMetaDataSanitize(t *testing.T) {
"time": time.Date(2023, 12, 5, 23, 59, 59, 123456789, time.UTC),
"duration": 105567462 * time.Millisecond,
"text": _textMarshaller{},
"json": json.RawMessage(`{"hello": "world"}`),
"array": []hash{{
"creditcard": "1234567812345678",
"broken": broken,
Expand All @@ -240,6 +242,7 @@ func TestMetaDataSanitize(t *testing.T) {
"time": "2023-12-05T23:59:59.123456789Z",
"duration": "29h19m27.462s",
"text": "marshalled text",
"json": `{"hello": "world"}`,
"array": []interface{}{map[string]interface{}{
"creditcard": "[FILTERED]",
"broken": map[string]interface{}{
Expand Down

0 comments on commit 2fa53ac

Please sign in to comment.