-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bug when marshal nil interface{} that contains not-indirect value (
#756)
- Loading branch information
Showing
4 changed files
with
54 additions
and
20 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package issue_test | ||
|
||
import ( | ||
"testing" | ||
"github.com/bytedance/sonic" | ||
) | ||
|
||
func TestIssue755_NilEfaceWithDirectValue(t *testing.T) { | ||
tests := []interface{} { | ||
struct { | ||
Foo *int | ||
}{}, | ||
struct { | ||
Foo func() | ||
}{}, | ||
chan int(nil), | ||
} | ||
for _, v := range(tests) { | ||
assertMarshal(t, sonic.ConfigDefault, v) | ||
} | ||
} | ||
|
||
type NilMarshaler struct {} | ||
|
||
func (n *NilMarshaler) MarshalJSON() ([]byte, error) { | ||
if n == nil { | ||
return []byte(`"my null value"`), nil | ||
} | ||
return []byte(`{}`), nil | ||
} | ||
|
||
func TestIssue755_MarshalIface(t *testing.T) { | ||
tests := []interface{} { | ||
&NilMarshaler{}, | ||
(*NilMarshaler)(nil), | ||
} | ||
for _, v := range(tests) { | ||
assertMarshal(t, sonic.ConfigDefault, v) | ||
} | ||
} | ||
|