diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 04:49:56 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 04:49:56 +0000 |
| commit | 9bb5c50d0b30b4dfb82b6b705dfcbf0e126a9d61 (patch) | |
| tree | e41fbeb90e4050ea2af6d37e7b443cf9f84be162 /lib/puppet/parser | |
| parent | be711d357857f5e6d4a28a22bd60dd89e9e136c0 (diff) | |
| download | puppet-9bb5c50d0b30b4dfb82b6b705dfcbf0e126a9d61.tar.gz puppet-9bb5c50d0b30b4dfb82b6b705dfcbf0e126a9d61.tar.xz puppet-9bb5c50d0b30b4dfb82b6b705dfcbf0e126a9d61.zip | |
Not downcasing facts any longer, closing #210 (although not using the patch from mpalmer, since I had not noticed the patch was there). Also, making all nodes, classes, and definitions case insensitive, closing #344. Finally, I added case insensitivity to the language in general, which should preserve backwards compatibility and probably makes the most sense in the long run anyway.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1964 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/ast.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/casestatement.rb | 11 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/selector.rb | 10 | ||||
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 12 |
4 files changed, 35 insertions, 12 deletions
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index ccd6d216a..e8cfcc4dd 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -80,24 +80,18 @@ class Puppet::Parser::AST # correctly handles errors. It is critical to use this method because # it can enable you to catch the error where it happens, rather than # much higher up the stack. - def safeevaluate(*args) + def safeevaluate(options) # We duplicate code here, rather than using exceptwrap, because this # is called so many times during parsing. - #exceptwrap do - # self.evaluate(*args) - #end begin - return self.evaluate(*args) + return self.evaluate(options) rescue Puppet::Error => detail raise adderrorcontext(detail) rescue => detail - message = options[:message] || "%s failed with error %s: %s" % - [self.class, detail.class, detail.to_s] - - error = options[:type].new(message) + error = Puppet::Error.new(detail.to_s) # We can't use self.fail here because it always expects strings, # not exceptions. - raise adderrorcontext(error, detail) + raise adderrorcontext(error) end end diff --git a/lib/puppet/parser/ast/casestatement.rb b/lib/puppet/parser/ast/casestatement.rb index 6543293b4..b4197d9b4 100644 --- a/lib/puppet/parser/ast/casestatement.rb +++ b/lib/puppet/parser/ast/casestatement.rb @@ -11,13 +11,21 @@ class Puppet::Parser::AST def evaluate(hash) scope = hash[:scope] value = @test.safeevaluate(:scope => scope) + sensitive = Puppet[:casesensitive] + value = value.downcase if ! sensitive and value.respond_to?(:downcase) retvalue = nil found = false # Iterate across the options looking for a match. @options.each { |option| - if option.eachvalue(scope) { |opval| break true if opval == value } + if option.eachvalue(scope) { |opval| + opval = opval.downcase if ! sensitive and opval.respond_to?(:downcase) + # break true if opval == value + if opval == value + break true + end + } # we found a matching option retvalue = option.safeevaluate(:scope => scope) found = true @@ -31,6 +39,7 @@ class Puppet::Parser::AST retvalue = @default.safeevaluate(:scope => scope) else Puppet.debug "No true answers and no default" + retvalue = nil end end return retvalue diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb index 94b7a5583..ce421e491 100644 --- a/lib/puppet/parser/ast/selector.rb +++ b/lib/puppet/parser/ast/selector.rb @@ -18,10 +18,15 @@ class Puppet::Parser::AST # Get our parameter. paramvalue = @param.safeevaluate(:scope => scope) + + sensitive = Puppet[:casesensitive] + + if ! sensitive and paramvalue.respond_to?(:downcase) + paramvalue = paramvalue.downcase + end default = nil - #@values = [@values] unless @values.instance_of? AST::ASTArray unless @values.instance_of? AST::ASTArray or @values.instance_of? Array @values = [@values] end @@ -29,6 +34,9 @@ class Puppet::Parser::AST # Then look for a match in the options. @values.each { |obj| param = obj.param.safeevaluate(:scope => scope) + if ! sensitive && param.respond_to?(:downcase) + param = param.downcase + end if param == paramvalue # we found a matching option retvalue = obj.value.safeevaluate(:scope => scope) diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 5144c4970..a81b7939f 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -10,6 +10,12 @@ require 'puppet/parser/scope' class Puppet::Parser::Interpreter include Puppet::Util + + Puppet.setdefaults(:puppet, + :casesensitive => [false, + "Whether matching in case statements and selectors + should be case-sensitive. Case insensitivity is + handled by downcasing all values before comparison."]) Puppet.setdefaults("ldap", :ldapnodes => [false, @@ -239,6 +245,8 @@ class Puppet::Parser::Interpreter # The recursive method used to actually look these objects up. def fqfind(namespace, name, table) + namespace = namespace.downcase + name = name.downcase if name =~ /^::/ or namespace == "" return table[name.sub(/^::/, '')] end @@ -469,6 +477,7 @@ class Puppet::Parser::Interpreter # Create a new class, or merge with an existing class. def newclass(fqname, options = {}) + fqname = fqname.downcase if @definetable.include?(fqname) raise Puppet::ParseError, "Cannot redefine class %s as a definition" % fqname @@ -521,6 +530,7 @@ class Puppet::Parser::Interpreter # Create a new definition. def newdefine(fqname, options = {}) + fqname = fqname.downcase if @classtable.include?(fqname) raise Puppet::ParseError, "Cannot redefine class %s as a definition" % fqname @@ -551,6 +561,7 @@ class Puppet::Parser::Interpreter def newnode(names, options = {}) names = [names] unless names.instance_of?(Array) names.collect do |name| + name = name.to_s.downcase if other = @nodetable[name] @parser.error("Node %s is already defined at %s:%s; cannot redefine" % [other.name, other.file, other.line]) end @@ -585,6 +596,7 @@ class Puppet::Parser::Interpreter # Search for our node in the various locations. def nodesearch(*nodes) + nodes = nodes.collect { |n| n.to_s.downcase } # At this point, stop at the first source that defines # the node @nodesources.each do |source| |
