Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puppet-lint crash with new puppet 4 syntax #516

Closed
jlintz opened this issue Aug 8, 2016 · 5 comments · Fixed by #676
Closed

Puppet-lint crash with new puppet 4 syntax #516

jlintz opened this issue Aug 8, 2016 · 5 comments · Fixed by #676
Labels
Milestone

Comments

@jlintz
Copy link

jlintz commented Aug 8, 2016

Test case:

file { 'foo':
  owner   => 'test',
  content => "
    export bar=\"${join(hiera('test'), "," )}\"
  "
}

running puppet-lint test.pp

Results in

/Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint/lexer.rb:356:in `interpolate_string': undefined method `[]' for nil:NilClass (NoMethodError)
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint/lexer.rb:183:in `tokenise'
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint/checks.rb:25:in `load_data'
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint/checks.rb:53:in `run'
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint.rb:174:in `run'
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint/bin.rb:59:in `block in run'
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint/bin.rb:56:in `each'
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/lib/puppet-lint/bin.rb:56:in `run'
    from /Users/justin/.rbenv/versions/2.1.9/lib/ruby/gems/2.1.0/gems/puppet-lint-2.0.0/bin/puppet-lint:7:in `<top (required)>'
    from /Users/justin/.rbenv/versions/2.1.9/bin/puppet-lint:23:in `load'
    from /Users/justin/.rbenv/versions/2.1.9/bin/puppet-lint:23:in `<main>'

Puppet will properly parse this and execute it with expected behavior

@jlintz
Copy link
Author

jlintz commented Aug 8, 2016

Tracked this down to adding the delimeter parameter to the join function will trigger this and when removed it doesn't crash

@rnelson0
Copy link
Collaborator

It has to do with the double quotes inside the double quoted string.

  content => "
    export bar=\"${join(hiera('test'), "," )}\"
  "

This I believe is a strangely allowed format, because of the interpolation of $(function()), where you should not place unescaped double quotes within a double quoted string. Changing the delimiter to single quotes eliminates the issue.

@rnelson0
Copy link
Collaborator

I am not sure how we would properly find that. The first double quote should be the end of the string, after all. If you wanted to figure out a way to account for this, I believe it would involve tokenise() and interpolate_string(). I'm just not sure it SHOULD be done even if it can since it appears to violate expectations of allowed unescaped characters inside of a double quoted string.

@rnelson0
Copy link
Collaborator

Thanks to Henrik, found the puppet lexer does this with slurp_dqstring. This might be something to review in the 3.0.0 branch when we can leverage the puppet lexer.

@rnelson0 rnelson0 added this to the 3.0.0 milestone Dec 18, 2016
@markeganfuller
Copy link

Just a side note on temporary workarounds, whilst changing the quotes works fine for some strings if you're trying to insert a line break you need double quotes, in this case you can define it as a variable and use that instead:

$join_str = "\n"
postfix::hash { '/etc/postfix/virtual':
  content => "${ $virtual.join($join_str) }\n",
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants