Skip to content

Commit

Permalink
Merge pull request #903 from rodjek/gh-851
Browse files Browse the repository at this point in the history
(#851) Ensure heredoc ending tag is on its own line
  • Loading branch information
rodjek authored Nov 4, 2019
2 parents 8f66ab6 + f9f7937 commit d2fb4b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet-lint/lexer/string_slurper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def unenclosed_variable?

def parse_heredoc(heredoc_tag)
heredoc_name = heredoc_tag[%r{\A"?(.+?)"?(:.+?)?#{PuppetLint::Lexer::WHITESPACE_RE}*(/.*)?\Z}, 1]
end_heredoc_pattern = %r{\A\|?\s*-?\s*#{Regexp.escape(heredoc_name)}}
end_heredoc_pattern = %r{^\|?\s*-?\s*#{Regexp.escape(heredoc_name)}$}
interpolation = heredoc_tag.start_with?('"')

@segment_type = :HEREDOC
Expand Down
12 changes: 12 additions & 0 deletions spec/puppet-lint/lexer/string_slurper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,18 @@
describe '#parse_heredoc' do
subject(:segments) { described_class.new(heredoc).parse_heredoc(heredoc_tag) }

context 'when the heredoc text contains the tag' do
let(:heredoc) { %( SOMETHING else\n |-THING) }
let(:heredoc_tag) { 'THING' }

it 'terminates the heredoc at the closing tag' do
expect(segments).to eq([
[:HEREDOC, " SOMETHING else\n "],
[:HEREDOC_TERM, '|-THING'],
])
end
end

context 'when parsing a heredoc with interpolation disabled' do
context 'that is a plain heredoc' do
let(:heredoc) { %( SOMETHING\n ELSE\n :\n |-myheredoc) }
Expand Down

0 comments on commit d2fb4b4

Please sign in to comment.