浏览代码

Do not call MarshalText on yaml.Marshaler.

Fixes #58.
Gustavo Niemeyer 11 年之前
父节点
当前提交
1bf6a7ce15
共有 2 个文件被更改,包括 5 次插入2 次删除
  1. 1 2
      encode.go
  2. 4 0
      encode_test.go

+ 1 - 2
encode.go

@@ -74,8 +74,7 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
 			return
 		}
 		in = reflect.ValueOf(v)
-	}
-	if m, ok := iface.(encoding.TextMarshaler); ok {
+	} else if m, ok := iface.(encoding.TextMarshaler); ok {
 		text, err := m.MarshalText()
 		if err != nil {
 			fail(err)

+ 4 - 0
encode_test.go

@@ -356,6 +356,10 @@ type marshalerType struct {
 	value interface{}
 }
 
+func (o marshalerType) MarshalText() ([]byte, error) {
+	panic("MarshalText called on type with MarshalYAML")
+}
+
 func (o marshalerType) MarshalYAML() (interface{}, error) {
 	return o.value, nil
 }