From 3987001e27c7f331843e4df591bc839be1465c6b Mon Sep 17 00:00:00 2001 From: allen Date: Tue, 14 Jan 2020 14:14:02 +0800 Subject: [PATCH] fix issue #389 #411 --- config.go | 4 ++-- value_tests/raw_message_test.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 8c58fcb..2adcdc3 100644 --- a/config.go +++ b/config.go @@ -183,11 +183,11 @@ func (cfg *frozenConfig) validateJsonRawMessage(extension EncoderExtension) { encoder := &funcEncoder{func(ptr unsafe.Pointer, stream *Stream) { rawMessage := *(*json.RawMessage)(ptr) iter := cfg.BorrowIterator([]byte(rawMessage)) + defer cfg.ReturnIterator(iter) iter.Read() - if iter.Error != nil { + if iter.Error != nil && iter.Error != io.EOF { stream.WriteRaw("null") } else { - cfg.ReturnIterator(iter) stream.WriteRaw(string(rawMessage)) } }, func(ptr unsafe.Pointer) bool { diff --git a/value_tests/raw_message_test.go b/value_tests/raw_message_test.go index ff46e64..e38da7f 100644 --- a/value_tests/raw_message_test.go +++ b/value_tests/raw_message_test.go @@ -7,6 +7,9 @@ import ( func init() { marshalCases = append(marshalCases, json.RawMessage("{}"), + json.RawMessage("12345"), + json.RawMessage("3.14"), + json.RawMessage("-0.5e10"), struct { Env string `json:"env"` Extra json.RawMessage `json:"extra,omitempty"`