Are you sure this is Psych and not Syck? Psych raises a syntax error on
your example:
irb(main):001:0> require 'psych'
=> true
irb(main):002:0> require 'yaml'
=> true
irb(main):003:0> a = YAML.load %{
irb(main):004:0" --- !!omap
irb(main):005:0" a: 1
irb(main):006:0" b: 2
irb(main):007:0" }
Psych::SyntaxError: (<unknown>): mapping values are not allowed in this context at line 3 column 4
from /Users/aaron/.local/lib/ruby/2.0.0/psych.rb:203:in `parse'
from /Users/aaron/.local/lib/ruby/2.0.0/psych.rb:203:in `parse_stream'
from /Users/aaron/.local/lib/ruby/2.0.0/psych.rb:151:in `parse'
from /Users/aaron/.local/lib/ruby/2.0.0/psych.rb:127:in `load'
from (irb):3
from /Users/aaron/.local/bin/irb:12:in `<main>'
irb(main):008:0>
Can you provide a runnable test case to reproduce your error?
class TestYAMLOMap < Test::Unit::TestCase
def test_omap_round_trip
a = YAML.load "--- !!omap\n"a: 1\nb: 2\n"
s = a.to_yaml
assert s.index('!!omap')
end
end
Btw, just thought of something that might be important here. Technically a YAML OMap type is written:
--- !!omap
a: 1
b: 2
The additional array sequence ensures the order regardless of the parser. However, given Ruby's ordered hashes, it makes sense that it can handle both the array (sequence) and the hash (mapping) forms.
This issue was solved with changeset r35657.
Thomas, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
Psych::Omap objects rather than hashes. [Bug #6425]