+1

On Jul 26, 2009, at 9:03 AM, Brice Figureau wrote:

>
> Signed-off-by: Brice Figureau <[email protected]>
> ---
> lib/puppet/parser/scope.rb |    9 +++++++--
> spec/unit/parser/scope.rb  |   30 ++++++++++++++++++++++++++++++
> 2 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
> index 5b3c6d0..71b9be2 100644
> --- a/lib/puppet/parser/scope.rb
> +++ b/lib/puppet/parser/scope.rb
> @@ -331,12 +331,17 @@ class Puppet::Parser::Scope
>         ss = StringScanner.new(string)
>         out = ""
>         while not ss.eos?
> -            if ss.scan(/^\$\{((\w*::)*\w+)\}|^\$((\w*::)*\w+)/)
> +            if ss.scan(/^\$\{((\w*::)*\w+|[0-9]+)\}|^\$([0-9])|^\$ 
> ((\w*::)*\w+)/)
>                 # If it matches the backslash, then just retun the  
> dollar sign.
>                 if ss.matched == '\\$'
>                     out << '$'
>                 else # look the variable up
> -                    out << lookupvar(ss[1] || ss[3]).to_s || ""
> +                    # make sure $0-$9 are lookupable only if  
> ephemeral
> +                    var = ss[1] || ss[3] || ss[4]
> +                    if var and var =~ /^[0-9]+$/ and not ephemeral? 
> (var)
> +                        next
> +                    end
> +                    out << lookupvar(var).to_s || ""
>                 end
>             elsif ss.scan(/^\\(.)/)
>                 # Puppet.debug("Got escape: pos:%d; m:%s" % [ss.pos,  
> ss.matched])
> diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
> index 641a3f9..665b2ed 100755
> --- a/spec/unit/parser/scope.rb
> +++ b/spec/unit/parser/scope.rb
> @@ -223,6 +223,36 @@ describe Puppet::Parser::Scope do
>         end
>     end
>
> +    describe "when interpolating string" do
> +        (0..9).each do |n|
> +            it "should allow $#{n} to match" do
> +                @scope.setvar(n.to_s, "value", :ephemeral => true)
> +
> +                @scope.strinterp("$#{n}").should == "value"
> +            end
> +        end
> +
> +        (0..9).each do |n|
> +            it "should not allow $#{n} to match if not ephemeral" do
> +                @scope.setvar(n.to_s, "value", :ephemeral => false)
> +
> +                @scope.strinterp("$#{n}").should_not == "value"
> +            end
> +        end
> +
> +        it "should not allow $10 to match" do
> +            @scope.setvar("10", "value", :ephemeral => true)
> +
> +            @scope.strinterp('==$10==').should_not == "==value=="
> +        end
> +
> +        it "should not allow ${10} to match" do
> +            @scope.setvar("10", "value", :ephemeral => true)
> +
> +            @scope.strinterp('==${10}==').should == "==value=="
> +        end
> +    end
> +
>     describe "when setting ephemeral vars from matches" do
>         before :each do
>             @match = stub 'match', :is_a? => true
> -- 
> 1.6.0.2
>
>
> >


-- 
Somebody has to do something, and it's just incredibly pathetic that it
has to be us. --Jerry Garcia
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


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