Skip to content

Commit

Permalink
Add to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veqryn authored and DariaKunoichi committed Feb 28, 2024
1 parent bf8d8ab commit 76448ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions v2/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ func (s Sanitizer) Sanitize(data interface{}) interface{} {
// This also covers time.Duration
return data.String()

case encoding.TextUnmarshaler:
var b []byte
if err := data.UnmarshalText(b); err == nil {
case encoding.TextMarshaler:
if b, err := data.MarshalText(); err == nil {
return string(b)
}
}
Expand Down
16 changes: 16 additions & 0 deletions v2/metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package bugsnag

import (
stderrors "errors"
"reflect"
"testing"
"time"
"unsafe"

"github.com/bugsnag/bugsnag-go/v2/errors"
Expand All @@ -26,6 +28,12 @@ type _broken struct {
Data string
}

type _textMarshaller struct{}

func (_textMarshaller) MarshalText() ([]byte, error) {
return []byte("marshalled text"), nil
}

var account = _account{}
var notifier = New(Configuration{})

Expand Down Expand Up @@ -123,6 +131,10 @@ func TestMetaDataSanitize(t *testing.T) {
"unsafe": unsafe.Pointer(broken.Me),
"string": "string",
"password": "secret",
"error": stderrors.New("some error"),
"time": time.Date(2023, 12, 5, 23, 59, 59, 123456789, time.UTC),
"duration": 105567462 * time.Millisecond,
"text": _textMarshaller{},
"array": []hash{{
"creditcard": "1234567812345678",
"broken": broken,
Expand All @@ -144,6 +156,10 @@ func TestMetaDataSanitize(t *testing.T) {
"unsafe": "[unsafe.Pointer]",
"func": "[func()]",
"password": "[FILTERED]",
"error": "some error",
"time": "2023-12-05T23:59:59.123456789Z",
"duration": "29h19m27.462s",
"text": "marshalled text",
"array": []interface{}{map[string]interface{}{
"creditcard": "[FILTERED]",
"broken": map[string]interface{}{
Expand Down

0 comments on commit 76448ff

Please sign in to comment.