浏览代码

Call MarshalYAML on the result of MarshalYAML

Reported in #134.
Gustavo Niemeyer 7 年之前
父节点
当前提交
6cdc503e36
共有 2 个文件被更改,包括 11 次插入1 次删除
  1. 2 1
      encode.go
  2. 9 0
      encode_test.go

+ 2 - 1
encode.go

@@ -137,7 +137,8 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
 			e.nilv()
 			return
 		}
-		in = reflect.ValueOf(v)
+		e.marshal(tag, reflect.ValueOf(v))
+		return
 	case encoding.TextMarshaler:
 		text, err := value.MarshalText()
 		if err != nil {

+ 9 - 0
encode_test.go

@@ -396,6 +396,15 @@ var marshalTests = []struct {
 		map[string]string{"a": "你好 #comment"},
 		"a: '你好 #comment'\n",
 	},
+
+	// Ensure MarshalYAML also gets called on the result of MarshalYAML itself.
+	{
+		&marshalerType{marshalerType{true}},
+		"true\n",
+	}, {
+		&marshalerType{&marshalerType{true}},
+		"true\n",
+	},
 }
 
 func (s *S) TestMarshal(c *C) {