Issue #19632 has been updated by Henrik Lindberg.

Status changed from Unreviewed to Accepted

As I am working on lexer/parser issues I did some tests, and it works just fine 
to evaluate string interpolation with brackets.

The problem is in puppet/resource.rb where the method `extract_type_and_title` 
is called from the Resource initialize method (being
passed the type `:notify` and the argtitle as the string "thisisa[bug]", this 
triggers an extraction into type = 'thisisa' and title = 'bug'. 

Here is the logic:

<pre>
  def extract_type_and_title(argtype, argtitle)
    if    (argtitle || argtype) =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1,           
      $2            ]
    elsif argtitle                                         then [ argtype,      
      argtitle      ]
    elsif argtype.is_a?(Puppet::Type)                      then [ 
argtype.class.name, argtype.title ]
    elsif argtype.is_a?(Hash)                              then
      raise ArgumentError, "Puppet::Resource.new does not take a hash as the 
first argument. "+
        "Did you mean (#{(argtype[:type] || argtype["type"]).inspect}, 
#{(argtype[:title] || argtype["title"]).inspect }) ?"
    else raise ArgumentError, "No title provided and #{argtype.inspect} is not 
a valid resource reference"
    end
  end
</pre>

The resons why some examples work and not others are: given `thisis[not]abug` 
does not match the first regular expression, `Notify[foo]` references
a bona fide type (`Notify` and the later check that the type is valid does now 
(naturally) not fail.

I found no mention in documentation of this special support in a resource title 
for being able to override the type inside the title, and have no clue why this 
behavior is wanted. It seems reasonable to change the logic to accept a given 
type (not override it), or if type is not given, attempt to parse it from
the title (although being a very "magic" thing to do).

Accepting the issue.

----------------------------------------
Bug #19632: Bracket in resource title causes ArgumentError (lexer bug)
https://projects.puppetlabs.com/issues/19632#change-84735

Author: Reid Vandewiele
Status: Accepted
Priority: Normal
Assignee: 
Category: 
Target version: 
Affected Puppet version: 
Keywords: 
Branch: 


Running a command such as (or applying a manifests with a similar resource):

<pre>
puppet apply -e "notify { 'thisisa[bug]': }"
</pre>

Results in

<pre>
Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource 
type notify at line 1 on node pseudonix.local
</pre>

However, the following works just fine.

<pre>
[reid@pseudonix:~] % puppet apply -e "notify { 'Notify[foo]': message => \$name 
}"
notice: main
notice: /Stage[main]//Notify[foo]/message: defined 'message' as 'main'
notice: Finished catalog run in 0.03 seconds
</pre>

Also working fine is:

<pre>
[reid@pseudonix:~] % puppet apply -e "notify { 'thisis[not]abug': }"
notice: thisis[not]abug
notice: /Stage[main]//Notify[thisis[not]abug]/message: defined 'message' as 
'thisis[not]abug'
notice: Finished catalog run in 0.03 seconds
</pre>

This appears to be a bug in the lexer and is triggered by any resource name 
ending in a closing bracket with a matching opening bracket earlier in the 
string. 


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to