Please review pull request #727: (#8778) Make '' == undef commutative in the DSL opened by (jeffmccune)
Description:
Without this patch applied the Puppet DSL treats undef == '' as true
but '' == undef as false. This is undesirable because the equality
operator should be commutative.
This patch fixes the problem by adding an explicit check for '' == undef
in the AST. Without this patch applied, Puppet already has an explicit
check for undef == '' but not for '' == undef.
The spec tests are also updated by this patch to reflect the change.
- Opened: Mon Apr 30 16:44:02 UTC 2012
- Based on: puppetlabs:2.7.x (24d4bb51d07f1c643d6c2277b4901f2044a51a6d)
- Requested merge: jeffmccune:ticket/2.7.x/8778_equality_in_puppet_is_not_commutative (229a9d49134bd366d57744347f7768b5e4e28023)
Diff follows:
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
index 122b4dd..8918d22 100644
--- a/lib/puppet/parser/ast.rb
+++ b/lib/puppet/parser/ast.rb
@@ -103,7 +103,7 @@ def evaluate_match(value, scope)
value = Puppet::Parser::Scope.number?(value) || value
# "" == undef for case/selector/if
- obj == value or (obj == "" and value == :undef)
+ obj == value or (obj == "" and value == :undef) or (obj == :undef and value == "")
end
end
diff --git a/spec/unit/parser/ast_spec.rb b/spec/unit/parser/ast_spec.rb
index 4d48712..4b2e1bb 100755
--- a/spec/unit/parser/ast_spec.rb
+++ b/spec/unit/parser/ast_spec.rb
@@ -1,4 +1,4 @@
-#!/usr/bin/env rspec
+#!/usr/bin/env ruby -S rspec
require 'spec_helper'
require 'puppet/parser/ast'
@@ -102,9 +102,9 @@ def safeevaluate(*options)
@evaluateable.evaluate_match(parameter, @scope)
end
- it "should not match '' if value is undef" do
+ it "should match '' if value is undef" do
@evaluateable.value = :undef
- @evaluateable.evaluate_match('', @scope).should be_false
+ @evaluateable.evaluate_match('', @scope).should be_true
end
end
end
-- 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.
