summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/psych/visitors/to_ruby.rb6
-rw-r--r--lib/psych/visitors/yaml_tree.rb1
-rw-r--r--test/psych/test_alias_and_anchor.rb28
3 files changed, 34 insertions, 1 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 1289ff9..2790cde 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -74,6 +74,8 @@ module Psych
}
args.push(args.delete_at(1) == '...')
Range.new(*args)
+ when /^!ruby\/sym(bol)?:?(.*)?$/
+ o.value.to_sym
else
@ss.tokenize o.value
end
@@ -170,7 +172,9 @@ module Psych
when /^!ruby\/object:?(.*)?$/
name = $1 || 'Object'
- revive((resolve_class(name) || Object), o)
+ obj = revive((resolve_class(name) || Object), o)
+ @st[o.anchor] = obj if o.anchor
+ obj
else
hash = {}
@st[o.anchor] = hash if o.anchor
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 83f11bf..523cfe1 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -54,6 +54,7 @@ module Psych
end
map = append Nodes::Mapping.new(nil, tag, false)
+ register(o, map)
@stack.push map
dump_ivars(o, map)
diff --git a/test/psych/test_alias_and_anchor.rb b/test/psych/test_alias_and_anchor.rb
new file mode 100644
index 0000000..51b048f
--- /dev/null
+++ b/test/psych/test_alias_and_anchor.rb
@@ -0,0 +1,28 @@
+require 'minitest/autorun'
+require 'psych'
+
+module Psych
+ class TestAliasAndAnchor < MiniTest::Unit::TestCase
+
+ def test_mri_compatibility
+ yaml = <<EOYAML
+---
+- &id001 !ruby/object {}
+
+- *id001
+- *id001
+EOYAML
+ result = Psych.load yaml
+ result.each {|el| assert_same(result[0], el) }
+ end
+
+ def test_anchor_alias_round_trip
+ o = Object.new
+ original = [o,o,o]
+
+ yaml = Psych.dump original
+ result = Psych.load yaml
+ result.each {|el| assert_same(result[0], el) }
+ end
+ end
+end