Page MenuHomePhabricator
Paste P17824

YAML LOL
ActivePublic

Authored by Joe on Nov 24 2021, 4:40 PM.
Tags
None
Referenced Files
F34764931: YAML LOL
Nov 24 2021, 4:40 PM
Subscribers
test yaml file:
```
test:
- name: foo
params: &params
bar: baz
fixx: buxx
- name: bar
params:
bar: BAR
<<: *params
```
Ruby:
```
$ irb
irb(main):001:0> require yaml
irb(main):004:0> YAML.load_file('test.yaml')
=> {"test"=>[{"name"=>"foo", "params"=>{"bar"=>"baz", "fixx"=>"buxx"}}, {"name"=>"bar", "params"=>{"bar"=>"baz", "fixx"=>"buxx"}}]}
```
The incoming parameter wins!
Python:
```
$ python3
Python 3.9.9 (main, Nov 16 2021, 10:24:31)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> with open('test.yaml', 'r') as fh:
... yaml.safe_load(fh)
...
{'test': [{'name': 'foo', 'params': {'bar': 'baz', 'fixx': 'buxx'}}, {'name': 'bar', 'params': {'bar': 'BAR', 'fixx': 'buxx'}}]}
```
The local parameter wins!

Event Timeline

That's a bug in the Ruby implementation. The YAML 1.1 Merge Key spec says:

If the value associated with the key is a single mapping node, each of its key/value pairs is inserted into the current mapping, unless the key already exists in it.