[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:31:46 UTC 2010


The following commit has been merged in the upstream branch:
commit b581c2348e784ce5d857a4c1c0686399b87cc13f
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Wed Mar 3 20:35:46 2010 +0100

    Fix #3229 - use original value in case/selector regex matching
    
    The issue is that case/selectors are downcasing the value before it
    is compared to the options.
    Unfortunately regex are matching in a case sensitive way, which would
    make the following manifest fail:
    
    $var = "CaseSensitive"
    case $var {
      /CaseSensitive/: {
         notice("worked")
      }
      default: {
        fail "miserably"
      }
    }
    
    This patch fixes the issue by making sure the regexp match is done
    one the original (not downcased) value, but still doing a case
    sensitive match.
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/parser/ast/casestatement.rb b/lib/puppet/parser/ast/casestatement.rb
index 25b0fc6..64298ca 100644
--- a/lib/puppet/parser/ast/casestatement.rb
+++ b/lib/puppet/parser/ast/casestatement.rb
@@ -12,8 +12,6 @@ class Puppet::Parser::AST
         # the first option that matches.
         def evaluate(scope)
             value = @test.safeevaluate(scope)
-            sensitive = Puppet[:casesensitive]
-            value = value.downcase if ! sensitive and value.respond_to?(:downcase)
 
             retvalue = nil
             found = false
@@ -22,7 +20,7 @@ class Puppet::Parser::AST
             default = nil
             @options.each do |option|
                 option.eachopt do |opt|
-                    return option.safeevaluate(scope) if opt.evaluate_match(value, scope, :file => file, :line => line, :sensitive => sensitive)
+                    return option.safeevaluate(scope) if opt.evaluate_match(value, scope, :file => file, :line => line, :sensitive => Puppet[:casesensitive])
                 end
 
                 default = option if option.default?
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 0f427ef..4ad1f9f 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -13,12 +13,12 @@ class Puppet::Parser::AST
         # evaluate ourselves, and match
         def evaluate_match(value, scope, options = {})
             obj = self.safeevaluate(scope)
-            if ! options[:sensitive] && obj.respond_to?(:downcase)
-                obj = obj.downcase
+            if options[:sensitive]
+                obj   = obj.downcase   if obj.respond_to?(:downcase)
+                value = value.downcase if value.respond_to?(:downcase)
             end
             # "" == undef for case/selector/if
-            return true if obj == "" and value == :undef
-            obj == value
+            obj == value or (obj == "" and value == :undef)
         end
 
         def match(value)
diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb
index 84bc2a7..ce834b6 100644
--- a/lib/puppet/parser/ast/selector.rb
+++ b/lib/puppet/parser/ast/selector.rb
@@ -17,8 +17,6 @@ class Puppet::Parser::AST
 
             sensitive = Puppet[:casesensitive]
 
-            paramvalue = paramvalue.downcase if not sensitive and paramvalue.respond_to?(:downcase)
-
             default = nil
 
             unless @values.instance_of? AST::ASTArray or @values.instance_of? Array
diff --git a/spec/unit/parser/ast/casestatement.rb b/spec/unit/parser/ast/casestatement.rb
index 554e295..657648e 100755
--- a/spec/unit/parser/ast/casestatement.rb
+++ b/spec/unit/parser/ast/casestatement.rb
@@ -28,16 +28,6 @@ describe Puppet::Parser::AST::CaseStatement do
             @casestmt.evaluate(@scope)
         end
 
-        it "should downcase the evaluated test value if allowed" do
-            Puppet.stubs(:[]).with(:casesensitive).returns(false)
-            value = stub 'test'
-            @test.stubs(:safeevaluate).with(@scope).returns(value)
-
-            value.expects(:downcase)
-
-            @casestmt.evaluate(@scope)
-        end
-
         it "should scan each option" do
             @options.expects(:each).multiple_yields(@option1, @option2)
 
diff --git a/spec/unit/parser/ast/leaf.rb b/spec/unit/parser/ast/leaf.rb
index 0c1c586..4645860 100755
--- a/spec/unit/parser/ast/leaf.rb
+++ b/spec/unit/parser/ast/leaf.rb
@@ -40,6 +40,13 @@ describe Puppet::Parser::AST::Leaf do
 
             @leaf.evaluate_match(:undef, @scope).should be_true
         end
+
+        it "should downcase the parameter value if wanted" do
+            parameter = stub 'parameter'
+            parameter.expects(:downcase).returns("value")
+
+            @leaf.evaluate_match(parameter, @scope, :insensitive => true)
+        end
     end
 
     describe "when converting to string" do
@@ -240,6 +247,12 @@ describe Puppet::Parser::AST::Regex do
             @regex.evaluate_match("value", @scope)
         end
 
+        it "should not downcase the paramater value" do
+            @value.expects(:match).with("VaLuE")
+
+            @regex.evaluate_match("VaLuE", @scope)
+        end
+
         it "should set ephemeral scope vars if there is a match" do
             @scope.expects(:ephemeral_from).with(true, nil, nil)
 
diff --git a/spec/unit/parser/ast/selector.rb b/spec/unit/parser/ast/selector.rb
index 2ba83ad..f9a1efe 100755
--- a/spec/unit/parser/ast/selector.rb
+++ b/spec/unit/parser/ast/selector.rb
@@ -40,16 +40,6 @@ describe Puppet::Parser::AST::Selector do
             @selector.evaluate(@scope)
         end
 
-        it "should downcase the evaluated param value if allowed" do
-            Puppet.stubs(:[]).with(:casesensitive).returns(false)
-            value = stub 'param'
-            @param.stubs(:safeevaluate).with(@scope).returns(value)
-
-            value.expects(:downcase)
-
-            @selector.evaluate(@scope)
-        end
-
         it "should scan each option" do
             @values.expects(:each).multiple_yields(@value1, @value2)
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list