fix: ensure WebAppErrorPages id inited on decode, and return early as an empty map on encode

This commit is contained in:
Derrick Hammer 2024-03-03 04:41:52 -05:00
parent a02458b597
commit 9fbb0bb859
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 7 deletions

View File

@ -235,19 +235,21 @@ func (wafm *WebAppFileMap) DecodeMsgpack(decoder *msgpack.Decoder) error {
return nil
}
func (w WebAppErrorPages) EncodeMsgpack(enc *msgpack.Encoder) error {
err := enc.EncodeMapLen(len(w))
func (w *WebAppErrorPages) EncodeMsgpack(enc *msgpack.Encoder) error {
if w == nil || *w == nil {
return enc.EncodeMapLen(0)
}
err := enc.EncodeMapLen(len(*w))
if err != nil {
return err
}
for k, v := range w {
err = enc.EncodeInt(int64(k))
if err != nil {
for k, v := range *w {
if err := enc.EncodeInt(int64(k)); err != nil {
return err
}
err = enc.EncodeString(v)
if err != nil {
if err := enc.EncodeString(v); err != nil {
return err
}
}
@ -256,6 +258,10 @@ func (w WebAppErrorPages) EncodeMsgpack(enc *msgpack.Encoder) error {
}
func (w *WebAppErrorPages) DecodeMsgpack(dec *msgpack.Decoder) error {
if *w == nil {
*w = make(map[int]string)
}
mapLen, err := dec.DecodeMapLen()
if err != nil {
return err