diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2010-02-08 20:17:38 +0100 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | e93eab81a58282db5306de6fec42703795c85523 (patch) | |
tree | 86968377febee8044e168ef3f4e1e528e6e32120 /lib/puppet/parser/ast/selector.rb | |
parent | b8832725e2bf1933af0d583ddbd81c8a8db4ae8f (diff) | |
download | puppet-e93eab81a58282db5306de6fec42703795c85523.tar.gz puppet-e93eab81a58282db5306de6fec42703795c85523.tar.xz puppet-e93eab81a58282db5306de6fec42703795c85523.zip |
Fix #3155 - prevent error when using two matching regex in cascade
The following manifest:
case $var {
/match/: {
if $var =~ /matchagain/ {
}
}
}
is failing because the "=~" operators when matching sets an ephemeral
variable in the scope. But the case regex also did it, and since they
both belong to the same scope, and Puppet variables are immutables, the
scope raises an error.
This patch fixes this issue by adding to the current scope a stack
of ephemeral symbol tables. Each new match operator or case/selector
with regex adds a new scope. When we get out of the case/if/selector
structure the scope is reset to the ephemeral level we were when
entering it.
This way the following manifest produces the correct output:
case $var {
/match(rematch)/: {
notice("1. \$0 = $0, \$1 = $1")
if $var =~ /matchagain/ {
notice("2. \$0 = $0, \$1 = $1")
}
notice("3. \$0 = $0, \$1 = $1")
}
}
notice("4. \$0 = $0")
And the output is:
1. $0 = match, $1 = rematch
2. $0 = matchagain, $1 = rematch
3. $0 = match, $1 = rematch
4. $0 =
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser/ast/selector.rb')
-rw-r--r-- | lib/puppet/parser/ast/selector.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb index d27773c4b..647bdcde1 100644 --- a/lib/puppet/parser/ast/selector.rb +++ b/lib/puppet/parser/ast/selector.rb @@ -12,6 +12,7 @@ class Puppet::Parser::AST # Find the value that corresponds with the test. def evaluate(scope) + level = scope.ephemeral_level # Get our parameter. paramvalue = @param.safeevaluate(scope) @@ -35,7 +36,7 @@ class Puppet::Parser::AST self.fail Puppet::ParseError, "No matching value for selector param '%s'" % paramvalue ensure - scope.unset_ephemeral_var + scope.unset_ephemeral_var(level) end def to_s |