diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-11-21 23:22:53 +0100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-12-29 18:45:47 +1100 |
commit | 53869e99149be0f60b4e415d061a76ab5421eadb (patch) | |
tree | 0e69b24905344745928909f3b5ae0c5a195772a5 /lib | |
parent | d921c459c14f7460fb209dea3b9194c91fee9fd1 (diff) | |
download | puppet-53869e99149be0f60b4e415d061a76ab5421eadb.tar.gz puppet-53869e99149be0f60b4e415d061a76ab5421eadb.tar.xz puppet-53869e99149be0f60b4e415d061a76ab5421eadb.zip |
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 <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/ast/leaf.rb | 7 |
1 files changed, 6 insertions, 1 deletions
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 |