diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2010-07-16 10:22:27 +0200 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-18 19:44:17 -0700 |
| commit | b509032e559cb26e05863b2c290a543c6fa9d779 (patch) | |
| tree | 49aa9f021c3f5775fad4b4e6a9fa1095017944e5 /lib/puppet/parser | |
| parent | 8c8c1469ae9f1dd11c567d89a27be81653ca2052 (diff) | |
| download | puppet-b509032e559cb26e05863b2c290a543c6fa9d779.tar.gz puppet-b509032e559cb26e05863b2c290a543c6fa9d779.tar.xz puppet-b509032e559cb26e05863b2c290a543c6fa9d779.zip | |
Fix #4238 - if should match undef as ''
The comparisons operator (and more particularly == and !=) were not treating
the undef value as '', like case and selector did since #2818.
This patch makes sure comparison operator uses AST leaf matching.
Unfortunately, doing this introduces a behavior change compared to
the previous versions:
Numbers embedded in strings will now be matched as numbers in case and
selector statements instead of string matching.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/ast/comparison_operator.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/leaf.rb | 3 |
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/puppet/parser/ast/comparison_operator.rb b/lib/puppet/parser/ast/comparison_operator.rb index c8694bbff..039c81df8 100644 --- a/lib/puppet/parser/ast/comparison_operator.rb +++ b/lib/puppet/parser/ast/comparison_operator.rb @@ -16,17 +16,16 @@ class Puppet::Parser::AST def evaluate(scope) # evaluate the operands, should return a boolean value lval = @lval.safeevaluate(scope) - rval = @rval.safeevaluate(scope) - # convert to number if operands are number - lval = Puppet::Parser::Scope.number?(lval) || lval - rval = Puppet::Parser::Scope.number?(rval) || rval + case @operator + when "==","!=" + @rval.evaluate_match(lval, scope) ? @operator == '==' : @operator == '!=' + else + rval = @rval.safeevaluate(scope) + rval = Puppet::Parser::Scope.number?(rval) || rval + lval = Puppet::Parser::Scope.number?(lval) || lval - # return result - unless @operator == '!=' lval.send(@operator,rval) - else - lval != rval end end diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index 3b9163d9c..49f430278 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -17,6 +17,9 @@ class Puppet::Parser::AST obj = obj.downcase if obj.respond_to?(:downcase) value = value.downcase if value.respond_to?(:downcase) + obj = Puppet::Parser::Scope.number?(obj) || obj + value = Puppet::Parser::Scope.number?(value) || value + # "" == undef for case/selector/if obj == value or (obj == "" and value == :undef) end |
