Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML inheritance broken when using yaml.MapSlice #91

Closed
mattes opened this issue Mar 24, 2015 · 8 comments
Closed

YAML inheritance broken when using yaml.MapSlice #91

mattes opened this issue Mar 24, 2015 · 8 comments

Comments

@mattes
Copy link

mattes commented Mar 24, 2015

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}]}]
}
@amolokoedov
Copy link

Not yet fixed. Is there a patch for this?

vinzenz pushed a commit to vinzenz/yaml that referenced this issue Nov 2, 2016
Signed-off-by: Vinzenz Feenstra <evilissmo@redhat.com>
vinzenz pushed a commit to vinzenz/yaml that referenced this issue Nov 2, 2016
Signed-off-by: Vinzenz Feenstra <evilissmo@redhat.com>
@vinzenz
Copy link

vinzenz commented Nov 2, 2016

@mattes @amolokoedov Would be cool if you could check that your use cases are covered with the PR I have sent

vinzenz pushed a commit to vinzenz/yaml that referenced this issue Nov 3, 2016
Signed-off-by: Vinzenz Feenstra <evilissmo@redhat.com>
vinzenz pushed a commit to vinzenz/yaml that referenced this issue Mar 27, 2017
Signed-off-by: Vinzenz Feenstra <evilissmo@redhat.com>
vinzenz pushed a commit to vinzenz/yaml that referenced this issue Sep 20, 2017
Signed-off-by: Vinzenz Feenstra <evilissmo@redhat.com>
@rogpeppe
Copy link
Contributor

@vinzenz I cannot find a description of the << operator in any of the YAML 1.x specifications.

Should this actually be a supported feature?

@vinzenz
Copy link

vinzenz commented Sep 20, 2017

@rogpeppe
Copy link
Contributor

@vinzenz How many other "working drafts" are actually part of the YAML spec without being mentioned there? How is one supposed to know what YAML actually is without a full specification?

@vinzenz
Copy link

vinzenz commented Sep 20, 2017

@rogpeppe Well I don't know, YAML is a beast ;-) I just added the support for MapSlice - Merge support was there already before

@hjdr4
Copy link

hjdr4 commented Feb 11, 2018

I need to use both merge and override and keep order.
Using vinzenz@764aa8c I'm able to use merge with MapSlice but overriding a merged key does not work, keys are just duplicated.

@niemeyer
Copy link
Contributor

I'd like to put a tombstone on this issue. MapSlice will die in v3, and be replaced by a much more flexible intermediate representation. I want to focus on that instead, and anyone that really wants such MapSlices and merges, which is not quite common, can move forward and migrate into it.

v3 is on the way and coming soon.

laszlocph added a commit to laszlocph/yaml that referenced this issue Nov 14, 2019
* v/fix-for-issue-91: (40 commits)
  Add test cases from go-yaml#184
  Fix for issue go-yaml#91
  Fixes go-yaml#214 - New option to allow setting strict boolean mode
  Fix for issue go-yaml#144
  Always use the pointer mechanism, but only allow recursion per option
  Applied API changes as suggested in another PR and fixed outstanding problems
  Removed introduced shadowing bug
  Make aliases share the same memory address as the anchor ( go-yaml#215 )
  Replace LICENSE text with actual license (go-yaml#274)
  Make tag scanning code slightly cleaner.
  move embedded struct example into godoc
  Add UnmarshalStrict returning error if yaml has fields that do not exist in structure
  correct misspell on yamlh.go
  fix misspell on emmiterc.go
  Remove unreachable code to fix go vet (go-yaml#249)
  Fix dead URL for yaml specification (go-yaml#240)
  Tighten restrictions on float decoding (go-yaml#171)
  Fix decode test for Go 1.8 (go-yaml#217)
  Fix unmarshaler handling of empty strings.
  new license in the README file (go-yaml#189)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants