Crash when trying to parse facts with unquoted keys
chutzimir opened this issue · comments
Describe the Bug
bundle exec puppet lint foo.pp; echo $?
puppet-lint version: 3.4.0
ruby version: 3.1.2-p20
platform: x86_64-linux
file path: foo.pp
file contents:
class foo { notify { $::facts[bar]: }
error:
NoMethodError: undefined method `[]' for nil:NilClass
fact_name = token.value.match(%r{::facts\['(.*)'\]})[1]
^^^
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb:121:in `block in check'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb:115:in `each'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb:115:in `check'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:21:in `run'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:61:in `block in run'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:58:in `each'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:58:in `run'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint.rb:224:in `run'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:84:in `block in run'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `each'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `run'
/tmp/bug/.bundle/gems/ruby/3.1.0/gems/puppet-lint-3.4.0/bin/puppet-lint:7:in `<top (required)>'
/tmp/bug/.bundle/gems/ruby/3.1.0/bin/puppet-lint:25:in `load'
/tmp/bug/.bundle/gems/ruby/3.1.0/bin/puppet-lint:25:in `<main>'
1
Expected Behavior
$ bundle exec puppet lint foo.pp; echo $?
0
Steps to Reproduce
$ cat > Gemfile <<EOF
source "https://rubygems.org"
gem 'puppet'
gem 'puppet-lint'
EOF
echo 'class foo { notify { $::facts[bar]: }' > foo.pp
bundle exec puppet lint foo.pp
Environment
- puppet-lint version: 3.4.0
- ruby version: 3.1.2-p20
- platform: x86_64-linux
- Platform
$ facter os.distro { codename => "Blue Onyx", description => "Rocky Linux release 9.1 (Blue Onyx)", id => "Rocky", release => { full => "9.1", major => "9", minor => "1" } }
Additional Context
For what it's worth, this started happening with version 3.2.0