Skip to content

Commit

Permalink
Merge pull request #1142 from shogo82148/copy-json-data-of-ephemera-key
Browse files Browse the repository at this point in the history
Copy the JSON data of EphemeralKey
  • Loading branch information
brandur-stripe authored Jul 27, 2020
2 parents c24b510 + a40214c commit 110e83d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ephemeralkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func (e *EphemeralKey) UnmarshalJSON(data []byte) error {
*e = EphemeralKey(ee)
}

e.RawJSON = data
// 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
}

0 comments on commit 110e83d

Please sign in to comment.