Parsing repeated mapping keys according to spec
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
goyaml |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
According to http://
However, goyaml has a mixed behavior when unmarshalling repeated keys depending on the type of the value. As it's shown by the code below.
If the value is a scalar, the last value is unmarshalled. If the value is a sequence, items from both sequences are merged in one.
This doesn't follow the spec and it's not even consistent, since sometimes the key is overridden and sometimes it's merged.
IMHO goyaml should fail to parse YAML's with repeated keys since they are not valid, however some libraries in other languages (like ruby) always consider the last key as the valid one.
I think either option would be better than the current behavior.
```
package main
import (
"fmt"
"launchpad.
)
type conf struct {
Something string `yaml:"something"`
Other []string `yaml:"other"`
}
var yamlData = `
something: a
something: b
other:
- x1
other:
- x2
`
func main() {
config := new(conf)
goyaml.
fmt.
for _, val := range config.Other {
}
}
// Output:
// b
// x1
// x2
```
Changed in goyaml: | |
status: | New → Confirmed |