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 <[email protected]>
---
 lib/puppet/parser/ast/casestatement.rb |    4 ++--
 lib/puppet/parser/ast/leaf.rb          |    1 +
 lib/puppet/parser/ast/selector.rb      |    4 ++--
 spec/unit/parser/ast/casestatement.rb  |    6 ++++++
 spec/unit/parser/ast/leaf.rb           |    6 ++++++
 spec/unit/parser/ast/selector.rb       |    6 ++++++
 6 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lib/puppet/parser/ast/casestatement.rb 
b/lib/puppet/parser/ast/casestatement.rb
index 25b0fc6..8ef3ea1 100644
--- a/lib/puppet/parser/ast/casestatement.rb
+++ b/lib/puppet/parser/ast/casestatement.rb
@@ -13,7 +13,7 @@ class Puppet::Parser::AST
         def evaluate(scope)
             value = @test.safeevaluate(scope)
             sensitive = Puppet[:casesensitive]
-            value = value.downcase if ! sensitive and 
value.respond_to?(:downcase)
+            downcased_value = value.downcase if ! sensitive and 
value.respond_to?(:downcase)
 
             retvalue = nil
             found = false
@@ -22,7 +22,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(downcased_value, scope, :file => file, :line => line, 
:sensitive => sensitive, :original => value)
                 end
 
                 default = option if option.default?
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index c8ac6f7..d95a6d9 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -176,6 +176,7 @@ class Puppet::Parser::AST
         end
 
         def evaluate_match(value, scope, options = {})
+            value = options[:original] || value
             value = value.is_a?(String) ? value : value.to_s
 
             if matched = @value.match(value)
diff --git a/lib/puppet/parser/ast/selector.rb 
b/lib/puppet/parser/ast/selector.rb
index 84bc2a7..1ed1ad8 100644
--- a/lib/puppet/parser/ast/selector.rb
+++ b/lib/puppet/parser/ast/selector.rb
@@ -17,7 +17,7 @@ class Puppet::Parser::AST
 
             sensitive = Puppet[:casesensitive]
 
-            paramvalue = paramvalue.downcase if not sensitive and 
paramvalue.respond_to?(:downcase)
+            downcased_paramvalue = paramvalue.downcase if not sensitive and 
paramvalue.respond_to?(:downcase)
 
             default = nil
 
@@ -28,7 +28,7 @@ class Puppet::Parser::AST
             # Then look for a match in the options.
             @values.each do |obj|
                 # short circuit asap if we have a match
-                return obj.value.safeevaluate(scope) if 
obj.param.evaluate_match(paramvalue, scope, :file => file, :line => line, 
:sensitive => sensitive)
+                return obj.value.safeevaluate(scope) if 
obj.param.evaluate_match(downcased_paramvalue, scope, :file => file, :line => 
line, :sensitive => sensitive, :original => paramvalue)
 
                 # Store the default, in case it's necessary.
                 default = obj if obj.param.is_a?(Default)
diff --git a/spec/unit/parser/ast/casestatement.rb 
b/spec/unit/parser/ast/casestatement.rb
index 554e295..b60bdce 100755
--- a/spec/unit/parser/ast/casestatement.rb
+++ b/spec/unit/parser/ast/casestatement.rb
@@ -74,6 +74,12 @@ describe Puppet::Parser::AST::CaseStatement do
                 @casestmt.evaluate(@scope)
             end
 
+            it "should evaluate_match with the original non downcase value" do
+                @opval1.expects(:evaluate_match).with { |*arg| 
arg[2][:original] == "value" }
+
+                @casestmt.evaluate(@scope)
+            end
+
             it "should return the first matching evaluated option" do
                 @opval2.stubs(:evaluate_match).with { |*arg| arg[0] == "value" 
}.returns(true)
                 @option2.stubs(:safeevaluate).with(@scope).returns(:result)
diff --git a/spec/unit/parser/ast/leaf.rb b/spec/unit/parser/ast/leaf.rb
index fecfba3..027dee3 100755
--- a/spec/unit/parser/ast/leaf.rb
+++ b/spec/unit/parser/ast/leaf.rb
@@ -123,6 +123,12 @@ describe Puppet::Parser::AST::Regex do
             @regex.evaluate_match("value", @scope)
         end
 
+        it "should issue the original value if given" do
+            @value.expects(:match).with("originalvalue")
+
+            @regex.evaluate_match("value", @scope, :original => 
"originalvalue")
+        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..8fb65f7 100755
--- a/spec/unit/parser/ast/selector.rb
+++ b/spec/unit/parser/ast/selector.rb
@@ -103,6 +103,12 @@ describe Puppet::Parser::AST::Selector do
                 @selector.evaluate(@scope)
             end
 
+            it "should transmit the original non-downcased value to 
evaluate_match" do
+                @param1.expects(:evaluate_match).with { |*arg| 
arg[2][:original] == "value" }
+
+                @selector.evaluate(@scope)
+            end
+
             it "should transmit the AST file and line to evaluate_match" do
                 @selector.file = :file
                 @selector.line = :line
-- 
1.6.6.1

-- 
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.

Reply via email to