diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/to_ruby.rb | 2 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 7 | ||||
-rw-r--r-- | test/psych/test_merge_keys.rb | 20 |
4 files changed, 36 insertions, 1 deletions
@@ -1,3 +1,11 @@ +Sat Aug 30 06:00:26 2014 Aaron Patterson <aaron@tenderlovemaking.com> + + * ext/psych/lib/psych/visitors/to_ruby.rb: quoted "<<" strings + should not be treated as merge keys. + * ext/psych/lib/psych/visitors/yaml_tree.rb: hashes with keys + containing "<<" should roundtrip. + * test/psych/test_merge_keys.rb: test for change. Fixes GH #203 + Fri Aug 29 17:56:44 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com> * test/net/imap/test_imap_response_parser.rb: removed needless code. diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 234cabc7f9..984bc84ed3 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -305,7 +305,7 @@ module Psych key = accept(k) val = accept(v) - if key == '<<' + if key == '<<' && k.tag != "tag:yaml.org,2002:str" case v when Nodes::Alias begin diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index 96260daffa..d73d91aff8 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -16,10 +16,12 @@ module Psych def initialize @obj_to_id = {} @obj_to_node = {} + @targets = [] @counter = 0 end def register target, node + @targets << target @obj_to_node[target.object_id] = node end @@ -289,6 +291,11 @@ module Psych quote = false elsif o =~ /\n/ style = Nodes::Scalar::LITERAL + elsif o == '<<' + style = Nodes::Scalar::SINGLE_QUOTED + tag = 'tag:yaml.org,2002:str' + plain = false + quote = false elsif o =~ /^\W[^"]*$/ style = Nodes::Scalar::DOUBLE_QUOTED else diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb index ba8d2e77b3..8b263e5186 100644 --- a/test/psych/test_merge_keys.rb +++ b/test/psych/test_merge_keys.rb @@ -6,6 +6,26 @@ module Psych attr_reader :bar end + def test_roundtrip_with_chevron_key + h = {} + v = { 'a' => h, '<<' => h } + assert_cycle v + end + + def test_explicit_string + doc = Psych.load <<-eoyml +a: &me { hello: world } +b: { !!str '<<': *me } +eoyml + expected = { + "a" => { "hello" => "world" }, + "b" => { + "<<" => { "hello" => "world" } + } + } + assert_equal expected, doc + end + def test_mergekey_with_object s = <<-eoyml foo: &foo |