Przeglądaj źródła

encoder.marshal panics on nil pointers

func (e *encoder) marshal(tag string, in reflect.Value) should not try to perform any operations (call MarshalYAML() or MarshalText()) on nil pointers
Sergey Bogomolov 9 lat temu
rodzic
commit
a311394a2a
1 zmienionych plików z 1 dodań i 1 usunięć
  1. 1 1
      encode.go

+ 1 - 1
encode.go

@@ -60,7 +60,7 @@ func (e *encoder) must(ok bool) {
 }
 
 func (e *encoder) marshal(tag string, in reflect.Value) {
-	if !in.IsValid() {
+	if !in.IsValid() || in.Kind() == reflect.Ptr && in.IsNil() {
 		e.nilv()
 		return
 	}