Просмотр исходного кода

Do not call MarshalText on yaml.Marshaler.

Fixes #58.
Gustavo Niemeyer 11 лет назад
Родитель
Сommit
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
 }