summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/psych/emitter.c2
-rw-r--r--lib/psych/visitors/to_ruby.rb5
-rw-r--r--lib/psych/visitors/yast_builder.rb11
-rw-r--r--test/visitors/test_yast_builder.rb6
4 files changed, 21 insertions, 3 deletions
diff --git a/ext/psych/emitter.c b/ext/psych/emitter.c
index 126f174..aa68e06 100644
--- a/ext/psych/emitter.c
+++ b/ext/psych/emitter.c
@@ -150,7 +150,7 @@ static VALUE start_sequence(
yaml_sequence_start_event_initialize(
&event,
(yaml_char_t *)(Qnil == anchor ? NULL : StringValuePtr(anchor)),
- (yaml_char_t *)(Qnil == anchor ? NULL : StringValuePtr(tag)),
+ (yaml_char_t *)(Qnil == tag ? NULL : StringValuePtr(tag)),
Qtrue == implicit ? 1 : 0,
(yaml_sequence_style_t)NUM2INT(style)
);
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 84813ed..836c0b6 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -19,7 +19,10 @@ module Psych
end
def visit_Psych_Nodes_Sequence o
- o.children.map { |c| c.accept self }
+ list = []
+ @st[o.anchor] = list if o.anchor
+ o.children.each { |c| list.push c.accept self }
+ list
end
def visit_Psych_Nodes_Mapping o
diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb
index 5de56ae..5dd7dc5 100644
--- a/lib/psych/visitors/yast_builder.rb
+++ b/lib/psych/visitors/yast_builder.rb
@@ -8,6 +8,7 @@ module Psych
@tree = Nodes::Stream.new
@tree.children << Nodes::Document.new
@stack = @tree.children.dup
+ @st = {}
end
def accept target
@@ -57,7 +58,15 @@ module Psych
end
def visit_Array o
- @stack.push append Nodes::Sequence.new
+ if node = @st[o.object_id]
+ node.anchor = o.object_id.to_s
+ return append Nodes::Alias.new o.object_id.to_s
+ end
+
+ seq = Nodes::Sequence.new
+ @st[o.object_id] = seq
+
+ @stack.push append seq
o.each { |c| c.accept self }
@stack.pop
end
diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb
index 2832da9..e70713c 100644
--- a/test/visitors/test_yast_builder.rb
+++ b/test/visitors/test_yast_builder.rb
@@ -8,6 +8,12 @@ module Psych
@v = Visitors::YASTBuilder.new
end
+ def test_circular_list
+ a = []
+ 2.times { a << a }
+ assert_equal a.inspect, Psych.load(a.to_yaml).inspect
+ end
+
def test_scalar
assert_round_trip 'foo'
assert_round_trip ':foo'