Skip to content

Commit

Permalink
Avoid internal error for typoed namespace
Browse files Browse the repository at this point in the history
Fixes #853
  • Loading branch information
usev6 committed Feb 23, 2019
1 parent 3c379cf commit 0fbe52e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/puppet-lint/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def find_resource_type_token(index)
lbrace_idx = tokens[0..index].rindex do |token|
token.type == :LBRACE && token.prev_code_token.type != :QMARK
end

raise PuppetLint::SyntaxError, tokens[index] if lbrace_idx.nil?

tokens[lbrace_idx].prev_code_token
end

Expand Down
12 changes: 12 additions & 0 deletions spec/puppet-lint/data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
}
end
end

context 'when typo in namespace separator makes parser look for resource' do
let(:manifest) { '$testparam = $::module:;testparam' }

it 'raises a SyntaxError' do
expect {
data.resource_indexes
}.to raise_error(PuppetLint::SyntaxError) { |error|
expect(error.token).to eq(data.tokens[5])
}
end
end
end

describe '.insert' do
Expand Down

0 comments on commit 0fbe52e

Please sign in to comment.