From 8cd1540f82cbdf903c164bdbc2c7229e34a4178b Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 17 Sep 2010 16:42:40 -0700 Subject: [#4692] undefined variables cause :undef to be passed to functions The :undef symbol, which we use internally to distinguish between undefined variables and variables whose value is the empty string, is being leaked in calls to functions (e.g. "split"). This is a departure from 0.25.x behavior, where undefined variables evaluated to "". This patch restores the 0.25.x behavior. --- spec/unit/parser/ast/function_spec.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/unit/parser/ast/function_spec.rb b/spec/unit/parser/ast/function_spec.rb index c57c7f098..38e344157 100644 --- a/spec/unit/parser/ast/function_spec.rb +++ b/spec/unit/parser/ast/function_spec.rb @@ -61,20 +61,30 @@ describe Puppet::Parser::AST::Function do end it "should call the underlying ruby function" do - argument = stub 'arg', :safeevaluate => "nothing" + argument = stub 'arg', :safeevaluate => ["nothing"] Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument - @scope.expects(:function_exist).with("nothing") + @scope.expects(:function_exist).with(["nothing"]) + + func.evaluate(@scope) + end + + it "should convert :undef to '' in arguments" do + argument = stub 'arg', :safeevaluate => ["foo", :undef, "bar"] + Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument + + @scope.expects(:function_exist).with(["foo", "", "bar"]) func.evaluate(@scope) end it "should return the ruby function return for rvalue functions" do - argument = stub 'arg', :safeevaluate => "nothing" + argument = stub 'arg', :safeevaluate => ["nothing"] Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument - @scope.stubs(:function_exist).with("nothing").returns("returning") + @scope.stubs(:function_exist).with(["nothing"]).returns("returning") func.evaluate(@scope).should == "returning" end -- cgit