Don't let users attempt to alias/merge arrays
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 597
- Forks
- 223
- Avg merge
- 11h 23m
- Merged PRs (30d)
- 3
Description
I encountered the confusing behavior described below because I didn't realize that one couldn't merge arrays, only maps. Perhaps we should instead make the parser more strict and throw an error rather than producing the unexpected object structure?
The confusing behavior:
YAML.load("
# Bad! can't merge alias/arrays
foo: &foo
- a: 1
bar:
<<: *foo
")
=> {"foo"=>[{"a"=>1}], "bar"=>{"<<"=>[{"a"=>1}]}}
Note the appearance of the odd <<. I was expecting expected
{"foo"=>[{"a"=>1}], "bar"=>[{"a"=>1}]}
As discussed here, my error is that the problem is that &foo is an attempted alias for an array. It would have been ideal if the parser had indicated my error instead.
In case relevant:
ENV['RBENV_VERSION']
=> "2.4"
YAML.libyaml_version
=> [0, 1, 4]
(Also, not entirely sure if this request belongs here or at https://github.com/yaml/libyaml , please feel free to redirect me!)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the YAML.load example and inspect how Psych handles an alias used with the << merge key when the aliased value is an array. The change is done when this invalid array merge is rejected with an error instead of producing a hash containing the literal << key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100