Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bugsnag/bugsnag-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.3.1
Choose a base ref
...
head repository: bugsnag/bugsnag-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.4.0
Choose a head ref
  • 8 commits
  • 4 files changed
  • 3 contributors

Commits on Apr 12, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    woodruffw William Woodruff
    Copy the full SHA
    6a6ff19 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    woodruffw William Woodruff
    Copy the full SHA
    d749f5e View commit details
  3. Copy the full SHA
    b1ce8cb View commit details
  4. veqryn/marshal-json: add nested metadata tests

    veqryn committed Apr 12, 2024
    Copy the full SHA
    f6c5984 View commit details
  5. Merge pull request #226 from veqryn/veqryn/marshal-json

    Sanitize for metadata should also handler json and []byte
    DariaKunoichi authored Apr 12, 2024
    Copy the full SHA
    316933f View commit details
  6. Update version to 2.4.0

    DariaKunoichi committed Apr 12, 2024
    Copy the full SHA
    c659c10 View commit details

Commits on Apr 15, 2024

  1. Merge pull request #227 from bugsnag/release-2.4.0-next

    Update version to 2.4.0
    DariaKunoichi authored Apr 15, 2024
    Copy the full SHA
    245bce0 View commit details
  2. Merge pull request #228 from bugsnag/next

    ## 2.4.0 (2024-04-15)
    
    ### Enhancements
    
    * Sanitize for metadata should also handler json and []byte
      [#226](#226)
      [Chris Duncan](https://github.com/veqryn)
    DariaKunoichi authored Apr 15, 2024
    Copy the full SHA
    4ae0bc0 View commit details
Showing with 90 additions and 11 deletions.
  1. +8 −0 CHANGELOG.md
  2. +1 −1 v2/bugsnag.go
  3. +10 −1 v2/metadata.go
  4. +71 −9 v2/metadata_test.go
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.4.0 (2024-04-15)

### Enhancements

* Sanitize for metadata should also handler json and []byte
[#226](https://github.com/bugsnag/bugsnag-go/pull/226)
[Chris Duncan](https://github.com/veqryn)

## 2.3.1 (2024-03-18)

### Bug fixes
2 changes: 1 addition & 1 deletion v2/bugsnag.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import (
)

// Version defines the version of this Bugsnag notifier
const Version = "2.3.1"
const Version = "2.4.0"

var panicHandlerOnce sync.Once
var sessionTrackerOnce sync.Once
11 changes: 10 additions & 1 deletion v2/metadata.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package bugsnag

import (
"encoding"
"encoding/json"
"fmt"
"reflect"
"strings"
@@ -98,7 +99,7 @@ func (s sanitizer) Sanitize(data interface{}) interface{} {
}
}

// Handle certain well known interfaces and types
// Handle certain well known interfaces and types, in preferred order
switch dataT := data.(type) {
case error:
return dataT.Error()
@@ -114,6 +115,14 @@ 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)
}

case []byte:
return string(dataT)
}

switch t.Kind() {
80 changes: 71 additions & 9 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"
@@ -112,13 +113,13 @@ func TestMetadataAddPointer(t *testing.T) {

func TestMetadataAddNil(t *testing.T) {
md := MetaData{}
md.AddStruct("map", map[string]interface{}{
"data": _testStruct{Name: nil},
})

var nilMap map[string]interface{}
md.AddStruct("nilmap", nilMap)

var nilSlice []interface{}
md.AddStruct("nilSlice", nilSlice)

var nilError _testError
md.AddStruct("error", nilError)

@@ -137,20 +138,77 @@ func TestMetadataAddNil(t *testing.T) {
var marshalFullPtr = &_textMarshaller{}
md.AddStruct("marshalFullPtr", marshalFullPtr)

var nullJsonMarshaller json.RawMessage
md.AddStruct("nullJsonMarshaller", nullJsonMarshaller)

var nullJsonMarshallerPtr *json.RawMessage
md.AddStruct("nullJsonMarshallerPtr", nullJsonMarshallerPtr)

var emptyJsonMarshaller = &json.RawMessage{}
md.AddStruct("emptyJsonMarshaller", emptyJsonMarshaller)

var nilBytes []byte
md.AddStruct("nilBytes", nilBytes)

var nilBytesPtr *[]byte
md.AddStruct("nilBytesPtr", nilBytesPtr)

var emptyBytes = []byte{}
md.AddStruct("emptyBytes", emptyBytes)

md.AddStruct("map", map[string]interface{}{
"data": _testStruct{Name: nil},
"nilmap": nilMap,
"nilSlice": nilSlice,
"error": nilError,
"errorNilPtr": nilErrorPtr,
"timeUnset": timeVar,
"durationUnset": duration,
"marshalNilPtr": marshalNilPtr,
"marshalFullPtr": marshalFullPtr,
"nullJsonMarshaller": nullJsonMarshaller,
"nullJsonMarshallerPtr": nullJsonMarshallerPtr,
"emptyJsonMarshaller": emptyJsonMarshaller,
"nilBytes": nilBytes,
"nilBytesPtr": nilBytesPtr,
"emptyBytes": emptyBytes,
})

if !reflect.DeepEqual(md, MetaData{
"map": {
"data": map[string]interface{}{
"Name": "<nil>",
},
"nilmap": map[string]interface{}{},
"nilSlice": []interface{}{},
"error": "errorstr",
"errorNilPtr": "<nil>",
"timeUnset": "0001-01-01T00:00:00Z",
"durationUnset": "0s",
"marshalFullPtr": "marshalled text",
"marshalNilPtr": "<nil>",
"nullJsonMarshaller": "null",
"nullJsonMarshallerPtr": "<nil>",
"emptyJsonMarshaller": "",
"nilBytes": "",
"nilBytesPtr": "<nil>",
"emptyBytes": "",
},
"nilmap": map[string]interface{}{},
"Extra data": {
"error": "errorstr",
"errorNilPtr": "<nil>",
"timeUnset": "0001-01-01T00:00:00Z",
"durationUnset": "0s",
"marshalFullPtr": "marshalled text",
"marshalNilPtr": "<nil>",
"nilSlice": []interface{}{},
"error": "errorstr",
"errorNilPtr": "<nil>",
"timeUnset": "0001-01-01T00:00:00Z",
"durationUnset": "0s",
"marshalFullPtr": "marshalled text",
"marshalNilPtr": "<nil>",
"nullJsonMarshaller": "null",
"nullJsonMarshallerPtr": "<nil>",
"emptyJsonMarshaller": "",
"nilBytes": "",
"nilBytesPtr": "<nil>",
"emptyBytes": "",
},
}) {
t.Errorf("metadata.AddStruct didn't work: %#v", md)
@@ -215,6 +273,8 @@ 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(`{"json_property": "json_value"}`),
"bytes": []byte(`lots of bytes`),
"array": []hash{{
"creditcard": "1234567812345678",
"broken": broken,
@@ -240,6 +300,8 @@ func TestMetaDataSanitize(t *testing.T) {
"time": "2023-12-05T23:59:59.123456789Z",
"duration": "29h19m27.462s",
"text": "marshalled text",
"json": `{"json_property": "json_value"}`,
"bytes": "lots of bytes",
"array": []interface{}{map[string]interface{}{
"creditcard": "[FILTERED]",
"broken": map[string]interface{}{