From 53869e99149be0f60b4e415d061a76ab5421eadb Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sat, 21 Nov 2009 23:22:53 +0100 Subject: Fix #2818 - scope variable assigned with undef are not "undef" The following manifest doesn't work: $foo = undef case $foo { undef: { notice("undef") } default: { notice("defined") } } This is because "undef" scope variable are returned as an empty string. This patch introduces a behavior change: Now, unassigned variable usage returns also undef. This might produce some issues in existing manifests, although care has been taken to allow correct behavior in the most commonly used patterns. For instance: case $bar { undef: { notice("undef") } default: { notice("defined") } } will print "undef". But matching undef in case/selector/if will also match "". case $bar { "": { notice("empty") } default: { notice("defined") } } will print "empty". Of course "" doesn't match undef :-) Signed-off-by: Brice Figureau --- lib/puppet/parser/ast/leaf.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index 07bba1b4c..b583149b3 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -16,6 +16,8 @@ class Puppet::Parser::AST if ! options[:sensitive] && obj.respond_to?(:downcase) obj = obj.downcase end + # "" == undef for case/selector/if + return true if obj == "" and value == :undef obj == value end @@ -125,7 +127,10 @@ class Puppet::Parser::AST # not include syntactical constructs, like '$' and '{}'). def evaluate(scope) parsewrap do - return scope.lookupvar(@value) + if (var = scope.lookupvar(@value, false)) == :undefined + var = :undef + end + var end end -- cgit