summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-08-29 14:03:18 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-08-29 14:03:18 -0700
commit08092b0f089f914388bfdf4775fb260a80ef7361 (patch)
tree2e5d64942027fb8aa860592a9e3456c176231e65
parentde391773646546deb81f9ed0dabaa9c828356f98 (diff)
downloadpsych-08092b0f089f914388bfdf4775fb260a80ef7361.tar.gz
* 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 fixes #203
-rw-r--r--CHANGELOG.rdoc8
-rw-r--r--lib/psych/visitors/to_ruby.rb2
-rw-r--r--lib/psych/visitors/yaml_tree.rb5
-rw-r--r--test/psych/test_merge_keys.rb20
4 files changed, 34 insertions, 1 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc
index cd87b92..fa8bb2e 100644
--- a/CHANGELOG.rdoc
+++ b/CHANGELOG.rdoc
@@ -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
+
Wed Aug 6 03:41:21 2014 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/to_ruby.rb: backwards compatibility for
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 234cabc..984bc84 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/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/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 2afedb7..d73d91a 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -291,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 ba8d2e7..8b263e5 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