Skip to content

v0.16.2

@juliens juliens tagged this 03 Nov 16:36
On Go 1.27, json.Marshal panics with a nil pointer when a struct has a pointer to an interpreted struct that embeds a type with methods, for example jwt.NumericDate (struct { time.Time }):

    type Date struct{ time.Time }
    type Claims struct{ Exp *Date }
    json.Marshal(Claims{Exp: &Date{}}) // panic

reflect.StructOf copies the methods of the embedded field to the struct type, but not to its pointer type. encoding/json v2 checks the methods on the struct type, then calls them on the pointer.

With this change, such a field is not marked anonymous. The struct has no promoted methods for reflect, so json encodes it as {"Time":"..."}. Before, on Go 1.26, it was encoded as the time value. Method calls in interpreted code, like d.Unix(), still work.

_test/struct63.go covers it. Tests pass on Go 1.27.3 and 1.26.10. In the Traefik plugins conformance tests, the cookie-auth-inalbilal plugin works again, with no other change.
Assets 2
Loading