yml merging bug #20

Closed
andriytyurnikov opened this Issue Jun 26, 2011 · 4 comments

Projects

None yet

3 participants

defaults: &defaults
application: bzz

development:
<<: *defaults
application: WTF
facebook:
id: 42
secret: 424242
scope: email,publish_stream

Everything after <<: *defaults is lost

Owner

This is fixed in the currently released psych gem. Please use it.

@tenderlove tenderlove closed this Jun 26, 2011
bjones commented Aug 24, 2011

Not sure if it fixes this issue, or if it does, how to use the gem'd psych instead of the psych included in ruby 1.9.2. Thoughts?

[bjones@tigger ~]$ ruby -rpsych -ryaml -rerb -rpp -e 'pp YAML::load(ERB.new(IO.read("test.yaml")).result)'
{"default"=>{"adapter"=>"mysql2"},
"specific"=>{"database"=>"my_db"},
"development"=>{"database"=>"my_db"}}

[bjones@tigger ~]$ ruby -ryaml -rerb -rpp -e 'pp YAML::load(ERB.new(IO.read("test.yaml")).result)'
{"default"=>{"adapter"=>"mysql2"},
"specific"=>{"database"=>"my_db"},
"development"=>{"adapter"=>"mysql2", "database"=>"my_db"}}

[bjones@tigger ~]$ cat test.yaml
default: &default
adapter: mysql2

specific: &specific
database: my_db

development:
<<: *specific
<<: *default

Owner

@bjones You have to activate the gem before requiring:

gem "psych"
require "psych"
[aaron@mobile-166-129-085-113 ~]$ ruby -e'require "psych"; p Psych::VERSION'
"1.0.0"
[aaron@mobile-166-129-085-113 ~]$ ruby -e'gem "psych"; require "psych"; p Psych::VERSION'
"1.2.1"
[aaron@mobile-166-129-085-113 ~]$ 
bjones commented Aug 25, 2011

The original bug report has the order wrong on how the merge used to work. The defaults were last, and only applied if the key was not already set. Easy to see this in ruby 1.9.2 p290, the merged results are different depending on whether using psych or not. That said, the original code might not have followed YAML spec here, but then I can't actually find this behavior documented in the current YAML 1.2 spec anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment