summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@rimspace.net>2011-01-31 16:00:37 -0800
committerDaniel Pittman <daniel@rimspace.net>2011-01-31 17:07:29 -0800
commit3a125d486ba4555796840a93a01ca5055eb9e157 (patch)
tree16b5168b39a18b7cd00b2f8944c2148c47648421
parent5bba59a7126e150e0e1e671d331878f4a00e2b2b (diff)
downloadpuppet-3a125d486ba4555796840a93a01ca5055eb9e157.tar.gz
puppet-3a125d486ba4555796840a93a01ca5055eb9e157.tar.xz
puppet-3a125d486ba4555796840a93a01ca5055eb9e157.zip
Bug #5755 -- ZAML generates extra newline in some hash backreferences.
This data structure generates YAML with an extra newline that violates the syntax rules and all: list = [1] { :a => list, :b => list }.to_yaml This breaks real client use of the YAML catalogs, not to mention our own use of cached catalogs...
-rw-r--r--lib/puppet/util/zaml.rb7
-rwxr-xr-xspec/unit/util/zaml_spec.rb21
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/puppet/util/zaml.rb b/lib/puppet/util/zaml.rb
index 9fda5ae3b..6ac956565 100644
--- a/lib/puppet/util/zaml.rb
+++ b/lib/puppet/util/zaml.rb
@@ -59,13 +59,12 @@ class ZAML
@@previously_emitted_object = {}
@@next_free_label_number = 0
end
- def initialize(obj,indent)
- @indent = indent
+ def initialize(obj)
@this_label_number = nil
@@previously_emitted_object[obj.object_id] = self
end
def to_s
- @this_label_number ? ('&id%03d%s' % [@this_label_number, @indent]) : ''
+ @this_label_number ? ('&id%03d ' % @this_label_number) : ''
end
def reference
@this_label_number ||= (@@next_free_label_number += 1)
@@ -76,7 +75,7 @@ class ZAML
end
end
def new_label_for(obj)
- Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"} " : ' ')
+ Label.new(obj)
end
def first_time_only(obj)
if label = Label.for(obj)
diff --git a/spec/unit/util/zaml_spec.rb b/spec/unit/util/zaml_spec.rb
index f2bcefe01..59590c571 100755
--- a/spec/unit/util/zaml_spec.rb
+++ b/spec/unit/util/zaml_spec.rb
@@ -35,5 +35,26 @@ describe "Pure ruby yaml implementation" do
lambda { YAML.load(o.to_yaml) }.should_not raise_error
end
}
+
+ it "should handle references to Array in Hash values correctly" do
+ list = [1]
+ data = { "one" => list, "two" => list }
+ data.to_yaml.should == "--- \n two: &id001 \n - 1\n one: *id001"
+ expect { YAML.load(data.to_yaml).should == data }.should_not raise_error
+ end
+
+ it "should handle references to Hash in Hash values correctly" do
+ hash = { 1 => 1 }
+ data = { "one" => hash, "two" => hash }
+ data.to_yaml.should == "--- \n two: &id001 \n 1: 1\n one: *id001"
+ expect { YAML.load(data.to_yaml).should == data }.should_not raise_error
+ end
+
+ it "should handle references to Scalar in Hash" do
+ str = "hello"
+ data = { "one" => str, "two" => str }
+ data.to_yaml.should == "--- \n two: &id001 hello\n one: *id001"
+ expect { YAML.load(data.to_yaml).should == data }.should_not raise_error
+ end
end