From a40214c96ffa36adaf33581519a1f991e3479ddf Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Tue, 28 Jul 2020 06:10:06 +0900 Subject: [PATCH] add a comment about assigning `RawJSON` --- ephemeralkey.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ephemeralkey.go b/ephemeralkey.go index d648faee97..9bc8a7fdcc 100644 --- a/ephemeralkey.go +++ b/ephemeralkey.go @@ -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