Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

YAML inheritance broken when using yaml.MapSlice #91

@mattes

Description

@mattes

See comments in code below:

package main

import (
    "fmt"
    "gopkg.in/yaml.v2"
)

var body = `
foo: &foo
  some: "var"

bar:
  <<: *foo
`

type Foobar struct {
    Foo interface{}
    Bar interface{}
}

func main() {
    // works as expected
    f := &Foobar{}
    if err := yaml.Unmarshal([]byte(body), &f); err != nil {
        fmt.Println(err)
    }
    fmt.Printf("%+v\n", f) // &{Foo:map[some:var] Bar:map[some:var]}

    // fails parsing yaml inheritance
    f1 := &yaml.MapSlice{}
    if err := yaml.Unmarshal([]byte(body), &f1); err != nil {
        fmt.Println(err)
    }
    fmt.Printf("%+v\n", f1) // &[{Key:foo Value:[{Key:some Value:var}]} {Key:bar Value:[]}]
    // expected: &[{Key:foo Value:[{Key:some Value:var}]} {Key:bar Value:[{Key:some Value:var}]}]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions