Skip to content

Commit 0ff9257

Browse files
committed
Do not crash when referring to a fact key without quoting it
Fixes #118
1 parent cc275ca commit 0ff9257

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def check
117117

118118
# This matches legacy facts defined in the fact hash that use the top scope
119119
# fact assignment.
120-
if token.value.start_with?('::facts[')
120+
if token.value.start_with?("::facts['")
121121
fact_name = token.value.match(%r{::facts\['(.*)'\]})[1]
122122

123123
# This matches legacy facts defined in the fact hash.

spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@
121121
expect(problems).to have(1).problem
122122
end
123123
end
124+
125+
context 'top scoped fact variable using unquoted legacy facts hash variable in interpolation' do
126+
let(:code) { '$::facts[osfamily]' }
127+
128+
it 'detects a single problem' do
129+
expect(problems).to have(0).problem
130+
end
131+
end
124132
end
125133

126134
context 'with fix enabled' do

0 commit comments

Comments
 (0)