Skip to content

Commit

Permalink
backport fix for #4580 don't leave behind empty line inside skipped c…
Browse files Browse the repository at this point in the history
…onditional
  • Loading branch information
mojavelinux committed May 4, 2024
1 parent 8223d74 commit 63cc47c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.adoc
Expand Up @@ -18,7 +18,9 @@ This project utilizes semantic versioning.
// tag::compact[]
== Unreleased

_No changes since previous release._
Bug Fixes::

* Don't leave behind empty line inside skipped preprocessor conditional (#4580)

== 2.0.22 (2024-03-08) - @mojavelinux

Expand Down
4 changes: 4 additions & 0 deletions lib/asciidoctor/reader.rb
Expand Up @@ -820,6 +820,10 @@ def process_line line
return line unless @process_lines

if line.empty?
if @skipping
shift
return nil
end
@look_ahead += 1
return line
end
Expand Down
26 changes: 26 additions & 0 deletions test/reader_test.rb
Expand Up @@ -2203,6 +2203,19 @@ def process reader, target, attributes
assert_equal 4, reader.lineno
end

test 'peek_line returns nil if contents of skipped conditional is empty line' do
input = <<~'EOS'
ifdef::foobar[]
endif::foobar[]
EOS

doc = Asciidoctor::Document.new input
reader = doc.reader
assert_equal 1, reader.lineno
assert_nil reader.peek_line
end

test 'ifdef with defined attribute includes content' do
input = <<~'EOS'
ifdef::holygrail[]
Expand Down Expand Up @@ -2540,6 +2553,19 @@ def process reader, target, attributes
assert_equal 'Our quest is complete!', result
end

test 'ifdef around empty line does not introduce extra line' do
input = <<~'EOS'
before
ifdef::no-such-attribute[]
endif::[]
after
EOS

result = (Asciidoctor::Document.new input).reader.read
assert_equal %(before\nafter), result
end

test 'should log warning if endif is unmatched' do
input = <<~'EOS'
Our quest is complete!
Expand Down

0 comments on commit 63cc47c

Please sign in to comment.