+1 On Fri, Sep 17, 2010 at 4:51 PM, Paul Berry <[email protected]> wrote:
> 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. > > Signed-off-by: Paul Berry <[email protected]> > --- > lib/puppet/parser/ast/function.rb | 2 +- > spec/unit/parser/ast/function_spec.rb | 18 ++++++++++++++---- > 2 files changed, 15 insertions(+), 5 deletions(-) > > diff --git a/lib/puppet/parser/ast/function.rb > b/lib/puppet/parser/ast/function.rb > index 74023f6..80e6e65 100644 > --- a/lib/puppet/parser/ast/function.rb > +++ b/lib/puppet/parser/ast/function.rb > @@ -28,7 +28,7 @@ class Puppet::Parser::AST > end > > # We don't need to evaluate the name, because it's plaintext > - args = @arguments.safeevaluate(scope) > + args = @arguments.safeevaluate(scope).map { |x| x == :undef ? '' : x > } > > scope.send("function...@name}", args) > end > diff --git a/spec/unit/parser/ast/function_spec.rb > b/spec/unit/parser/ast/function_spec.rb > index c57c7f0..38e3441 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 > -- > 1.7.2 > > -- > 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]<puppet-dev%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. > > -- 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.
