Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/puppet-lint/plugins/check_unsafe_interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def get_exec_titles
# Check if title is double quotes string
elsif tokens[token_idx].next_code_token.next_code_token.type == :DQPRE
# Find the start and end of the title
title_start_idx = tokens.rindex { |r| r.type == :DQPRE }
title_end_idx = tokens.rindex { |r| r.type == :DQPOST }
title_start_idx = tokens.find_index(tokens[token_idx].next_code_token.next_code_token)
title_end_idx = title_start_idx + index_offset_for(':', tokens[title_start_idx..tokens.length])

result << tokens[title_start_idx..title_end_idx]
# Title is in single quotes
Expand All @@ -117,4 +117,13 @@ def get_exec_titles
def interpolated?(token)
INTERPOLATED_STRINGS.include?(token.type)
end

# Finds the index offset of the next instance of `value` in `tokens_slice` from the original index
def index_offset_for(value, tokens_slice)
i = 0
while i < tokens_slice.length
return i if value.include?(tokens_slice[i].value)
i += 1
end
end
end