Skip to content

Commit

Permalink
add a comment about assigning RawJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Jul 27, 2020
1 parent 9fec249 commit a40214c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ephemeralkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (e *EphemeralKey) UnmarshalJSON(data []byte) error {
*e = EphemeralKey(ee)
}

// Go does guarantee the longevity of `data`, so copy when assigning `RawJSON`
// See https://golang.org/pkg/encoding/json/#Unmarshaler
// and https://github.com/stripe/stripe-go/pull/1142
e.RawJSON = append(e.RawJSON[:0], data...)

return nil
Expand Down

0 comments on commit a40214c

Please sign in to comment.