Issue #8778 has been updated by Jeff McCune.

Status changed from In Topic Branch Pending Review to Merged - Pending Release
Target version changed from 2.7.x to 2.7.15

# Merged into 2.7.x #

As: 
<https://github.com/puppetlabs/puppet/commit/7af59dea8e6edee3147f3b049c0c35729db8ca64>

<pre>

commit 7af59dea8e6edee3147f3b049c0c35729db8ca64 (from 
24d4bb51d07f1c643d6c2277b4901f2044a51a6d)
Merge: 24d4bb5 a713f07
Author: Jeff McCune <[email protected]>
Date:   Mon Apr 30 10:01:38 2012 -0700

    Merge branch 'ticket/2.7.x/8778_equality_in_puppet_is_not_commutative' into 
2.7.x
    
    * ticket/2.7.x/8778_equality_in_puppet_is_not_commutative:
      (#8778) Make '' == undef commutative in the DSL
    
    Reviewed-by: James Turnbull

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 @@ class Puppet::Parser::AST
     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/leaf_spec.rb 
b/spec/unit/parser/ast/leaf_spec.rb
index d70dc65..94b2abb 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -1,4 +1,4 @@
-#!/usr/bin/env rspec
+#!/usr/bin/env ruby -S rspec
 require 'spec_helper'
 
 describe Puppet::Parser::AST::Leaf do
@@ -95,7 +95,7 @@ describe Puppet::Parser::AST::Undef do
   end
 
   it "should not match undef with an empty string" do
-    @undef.evaluate_match("", @scope).should be_false
+    @undef.evaluate_match("", @scope).should be_true
   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 @@ describe 'AST Generic Child' do
       @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
</pre>
----------------------------------------
Bug #8778: Equality in Puppet is not commutative
https://projects.puppetlabs.com/issues/8778#change-61640

Author: Jeff McCune
Status: Merged - Pending Release
Priority: Normal
Assignee: Daniel Pittman
Category: parser
Target version: 2.7.15
Affected Puppet version: 
Keywords: parser commutative undef empty string
Branch: https://github.com/puppetlabs/puppet/pull/727


# Overview #

The equality (`==`) test in Puppet is not commutative in combination with the 
undef value.

All three notices should print OR only "undef == undef" should print.  Two 
notices should NOT print.
<pre>
if undef == undef {
  notice("undef == undef")
}
if undef == '' {
  notice("undef == ''")
}
if '' == undef {
  notice("'' == undef")
}
</pre>

# Actual Behavior #

Notice that undef == '' but not '' == undef.

<pre>
notice: Scope(Class[main]): undef == undef
notice: Scope(Class[main]): undef == ''
notice: Finished catalog run in 0.02 seconds
</pre>



-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" 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-bugs?hl=en.

Reply via email to