This fixes double-quoted strings to interpolate undef variables
as an empty string. This is the behavior present in 0.25.x.

Signed-off-by: Nick Lewis <[email protected]>
---
 lib/puppet/parser/ast/leaf.rb     |    5 ++++-
 spec/unit/parser/ast/leaf_spec.rb |   31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 49f4302..781fc4b 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -77,7 +77,10 @@ class Puppet::Parser::AST
 
   class Concat < AST::Leaf
     def evaluate(scope)
-      @value.collect { |x| x.evaluate(scope) }.join
+      @value.collect do |x|
+        val = x.evaluate(scope)
+        val == :undef ? '' : val
+      end.join
     end
 
     def to_s
diff --git a/spec/unit/parser/ast/leaf_spec.rb 
b/spec/unit/parser/ast/leaf_spec.rb
index d21cbf5..2843567 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -107,6 +107,37 @@ describe Puppet::Parser::AST::String do
   end
 end
 
+describe Puppet::Parser::AST::Concat do
+  describe "when evaluating" do
+    before :each do
+      @scope = stub_everything 'scope'
+    end
+    it "should interpolate variables and concatenate their values" do
+      one = Puppet::Parser::AST::String.new(:value => "one")
+      one.stubs(:evaluate).returns("one ")
+      two = Puppet::Parser::AST::String.new(:value => "two")
+      two.stubs(:evaluate).returns(" two ")
+      three = Puppet::Parser::AST::String.new(:value => "three")
+      three.stubs(:evaluate).returns(" three")
+      var = Puppet::Parser::AST::Variable.new(:value => "myvar")
+      var.stubs(:evaluate).returns("foo")
+      array = Puppet::Parser::AST::Variable.new(:value => "array")
+      array.stubs(:evaluate).returns(["bar","baz"])
+      concat = Puppet::Parser::AST::Concat.new(:value => 
[one,var,two,array,three])
+
+      concat.evaluate(@scope).should == 'one foo two barbaz three'
+    end
+
+    it "should transform undef variables to empty string" do
+      var = Puppet::Parser::AST::Variable.new(:value => "myvar")
+      var.stubs(:evaluate).returns(:undef)
+      concat = Puppet::Parser::AST::Concat.new(:value => [var])
+
+      concat.evaluate(@scope).should == ''
+    end
+  end
+end
+
 describe Puppet::Parser::AST::Undef do
   before :each do
     @scope = stub 'scope'
-- 
1.7.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to