Skip to content

Commit

Permalink
fix: check valid first in fallback Unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Feb 14, 2024
1 parent e47ca10 commit 3413fac
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions compat.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !amd64 || !go1.16 || go1.22
// +build !amd64 !go1.16 go1.22

/*
Expand All @@ -19,12 +20,13 @@
package sonic

import (
`bytes`
`encoding/json`
`io`
`reflect`
"bytes"
"encoding/json"
"io"
"reflect"

`github.com/bytedance/sonic/option`
"github.com/bytedance/sonic/internal/rt"
"github.com/bytedance/sonic/option"
)

type frozenConfig struct {
Expand Down Expand Up @@ -85,6 +87,9 @@ func (cfg frozenConfig) UnmarshalFromString(buf string, val interface{}) error {
if cfg.DisallowUnknownFields {
dec.DisallowUnknownFields()
}
if !json.Valid(rt.Str2Mem(buf)) {
return json.Unmarshal(rt.Str2Mem(buf), val)
}
return dec.Decode(val)
}

Expand Down

0 comments on commit 3413fac

Please sign in to comment.