[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5rc1-120-g2247c80

Daniel Pittman daniel at rimspace.net
Mon Feb 7 06:42:03 UTC 2011


The following commit has been merged in the upstream branch:
commit 3a125d486ba4555796840a93a01ca5055eb9e157
Author: Daniel Pittman <daniel at rimspace.net>
Date:   Mon Jan 31 16:00:37 2011 -0800

    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...

diff --git a/lib/puppet/util/zaml.rb b/lib/puppet/util/zaml.rb
index 9fda5ae..6ac9565 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 f2bcefe..59590c5 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
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list