https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-05-14T08:53:24ZRuby Issue Tracking SystemRuby master - Bug #6425: Psych issue with !!omaphttps://bugs.ruby-lang.org/issues/6425?journal_id=266082012-05-14T08:53:24ZAnonymous
<ul><li><strong>File</strong> <a href="/attachments/2683">noname</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/2683/noname">noname</a> added</li></ul><p>On Sat, May 12, 2012 at 04:55:08AM +0900, trans (Thomas Sawyer) wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Psych issue with !!omap (Closed)" href="https://bugs.ruby-lang.org/issues/6425">#6425</a> has been reported by trans (Thomas Sawyer).</p>
<hr>
<p>Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Psych issue with !!omap (Closed)" href="https://bugs.ruby-lang.org/issues/6425">#6425</a>: Psych issue with !!omap<br>
<a href="https://bugs.ruby-lang.org/issues/6425" class="external">https://bugs.ruby-lang.org/issues/6425</a></p>
<p>Author: trans (Thomas Sawyer)<br>
Status: Open<br>
Priority: Normal<br>
Assignee:<br>
Category: lib<br>
Target version:<br>
ruby -v: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]</p>
<p>=begin</p>
<p>Psych doesn't seem to know ordered map. It parses fine, but loose the type when round-tripped.</p>
<h2>a = YAML.load %{<br>
--- !!omap<br>
a: 1<br>
b: 2<br>
}<br>
=> {"a"=>1, "b"=>2}<br>
a.class<br>
=> Hash<br>
puts a.to_yaml</h2>
<p>a: 1<br>
b: 2</p>
<p>=end</p>
</blockquote>
<p>Are you sure this is Psych and not Syck? Psych raises a syntax error on<br>
your example:</p>
<pre><code> 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>
</code></pre>
<p>Can you provide a runnable test case to reproduce your error?</p>
<p>--<br>
Aaron Patterson<br>
<a href="http://tenderlovemaking.com/" class="external">http://tenderlovemaking.com/</a></p> Ruby master - Bug #6425: Psych issue with !!omaphttps://bugs.ruby-lang.org/issues/6425?journal_id=266292012-05-15T08:45:04Ztrans (Thomas Sawyer)
<ul></ul><p>=begin</p>
<p>Ah, the indention I added was the problem. Try:</p>
<p>a = YAML.load %{<br>
--- !!omap<br>
a: 1<br>
b: 2<br>
}<br>
a.class<br>
a.to_yaml</p>
<p>As for a test case. Something like?</p>
<p>class TestYAMLOMap < Test::Unit::TestCase<br>
def test_omap_round_trip<br>
a = YAML.load "--- !!omap\n"a: 1\nb: 2\n"<br>
s = a.to_yaml<br>
assert s.index('!!omap')<br>
end<br>
end</p>
<p>Okay, it could be better, but it's a start.<br>
=end</p> Ruby master - Bug #6425: Psych issue with !!omaphttps://bugs.ruby-lang.org/issues/6425?journal_id=266402012-05-16T01:12:00Ztrans (Thomas Sawyer)
<ul></ul><p>Btw, just thought of something that might be important here. Technically a YAML OMap type is written:</p>
<p>--- !!omap</p>
<ul>
<li>a: 1</li>
<li>b: 2</li>
</ul>
<p>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.</p> Ruby master - Bug #6425: Psych issue with !!omaphttps://bugs.ruby-lang.org/issues/6425?journal_id=266412012-05-16T01:23:22ZAnonymous
<ul><li><strong>File</strong> <a href="/attachments/2685">noname</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/2685/noname">noname</a> added</li></ul><p>On Tue, May 15, 2012 at 08:45:05AM +0900, trans (Thomas Sawyer) wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Psych issue with !!omap (Closed)" href="https://bugs.ruby-lang.org/issues/6425">#6425</a> has been updated by trans (Thomas Sawyer).</p>
<p>=begin</p>
<p>Ah, the indention I added was the problem. Try:</p>
<p>a = YAML.load %{<br>
--- !!omap<br>
a: 1<br>
b: 2<br>
}<br>
a.class<br>
a.to_yaml</p>
</blockquote>
<p>Perfect. I can verify this is a bug. Thanks for reporting it!</p>
<p>--<br>
Aaron Patterson<br>
<a href="http://tenderlovemaking.com/" class="external">http://tenderlovemaking.com/</a></p> Ruby master - Bug #6425: Psych issue with !!omaphttps://bugs.ruby-lang.org/issues/6425?journal_id=266422012-05-16T01:34:23Ztenderlovemaking (Aaron Patterson)tenderlove@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r35657.<br>
Thomas, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>
<p>ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to<br>
Psych::Omap objects rather than hashes. [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Psych issue with !!omap (Closed)" href="https://bugs.ruby-lang.org/issues/6425">#6425</a>]</p>
</li>
<li>
<p>test/psych/test_omap.rb: pertinent test.</p>
</li>
</ul>