std.parseYaml: merge key (<<) conversion produces bogus "true" key and drops fields
- Dominant language
- Go
- Stars
- 1.8k
- Forks
- 263
- PR merge metrics
- No merged PRs in 30d
Description
## Description
`std.parseYaml` mishandles YAML merge keys (`<<: *anchor`): merged fields are replaced by a bogus `"true"` key, and the corruption can extend to the anchor sources themselves.
## Reproduction 1
```jsonnet
std.parseYaml("base: &b {x: 1}\nchild:\n <<: *b\n y: 2")
```
Actual (go-jsonnet v0.22.0):
```json
{
"base": {
"x": 1
},
"child": {
"true": 2,
"x": 1
}
}
```
Expected (YAML merge-key semantics):
```json
{
"base": {
"x": 1
},
"child": {
"x": 1,
"y": 2
}
}
```
## Reproduction 2 (multi-anchor merge)
```jsonnet
std.parseYaml("a: &a {x: 1}\nb: &b {y: 2}\nc:\n <<: [*a, *b]")
```
Actual:
```json
{
"a": {
"x": 1
},
"b": {
"true": 2
},
"c": {
"true": 2,
"x": 1
}
}
```
Expected:
```json
{
"a": {
"x": 1
},
"b": {
"y": 2
},
"c": {
"x": 1,
"y": 2
}
}
```
Note `b` is corrupted as well (`y` replaced by `"true"`), even though it is only referenced as an anchor.
## Notes
- It looks as if the merge-key sentinel (`<<`, represented as a boolean by the YAML library) leaks into converted mappings as the string `"true"`, displacing a real key.
- Both sjsonnet and jrsonnet produce the Expected output for both reproductions.
- Found while differential-testing sjsonnet against go-jsonnet.
Contributor guide
Research direction
Start by locating the implementation of std.parseYaml and the YAML-to-Jsonnet mapping conversion. Add regression cases for both reported reproductions, then verify that merge fields retain their names, multi-anchor merges work, and referenced anchor objects are not corrupted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, yaml
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100