Bug #6425
closed
Added by trans (Thomas Sawyer) almost 12 years ago.
Updated almost 12 years ago.
Description
=begin
Psych doesn't seem to know ordered map. It parses fine, but loose the type when round-tripped.
a = YAML.load %{
--- !!omap
a: 1
b: 2
}
=> {"a"=>1, "b"=>2}
a.class
=> Hash
puts a.to_yaml
a: 1
b: 2
=end
Files
On Sat, May 12, 2012 at 04:55:08AM +0900, trans (Thomas Sawyer) wrote:
Issue #6425 has been reported by trans (Thomas Sawyer).
Bug #6425: Psych issue with !!omap
https://bugs.ruby-lang.org/issues/6425
Author: trans (Thomas Sawyer)
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:
ruby -v: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
=begin
Psych doesn't seem to know ordered map. It parses fine, but loose the type when round-tripped.
a = YAML.load %{
--- !!omap
a: 1
b: 2
}
=> {"a"=>1, "b"=>2}
a.class
=> Hash
puts a.to_yaml
a: 1
b: 2
=end
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?
--
Aaron Patterson
http://tenderlovemaking.com/
=begin
Ah, the indention I added was the problem. Try:
a = YAML.load %{
--- !!omap
a: 1
b: 2
}
a.class
a.to_yaml
As for a test case. Something like?
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
Okay, it could be better, but it's a start.
=end
Btw, just thought of something that might be important here. Technically a YAML OMap type is written:
--- !!omap
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.
On Tue, May 15, 2012 at 08:45:05AM +0900, trans (Thomas Sawyer) wrote:
Issue #6425 has been updated by trans (Thomas Sawyer).
=begin
Ah, the indention I added was the problem. Try:
a = YAML.load %{
--- !!omap
a: 1
b: 2
}
a.class
a.to_yaml
Perfect. I can verify this is a bug. Thanks for reporting it!
--
Aaron Patterson
http://tenderlovemaking.com/
- Status changed from Open to Closed
- % Done changed from 0 to 100
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.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0