diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2024-05-04 10:45:03 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-04 08:45:03 -0600 |
| commit | ffab0363d1a9ab30124695991a023669aef41d5c (patch) | |
| tree | 72ab28ccc8fa5891d8d1c241acdb431a0db7de5e | |
| parent | 935a0a3a2fe05ba7d239d8e774ada20df5879599 (diff) | |
resolves #4580 don't leave behind empty line inside skipped conditional (PR #4582)
| -rw-r--r-- | CHANGELOG.adoc | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/reader.rb | 4 | ||||
| -rw-r--r-- | test/reader_test.rb | 26 |
3 files changed, 34 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index f664e1bd..e66d22b2 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -66,6 +66,10 @@ Improvements:: * Return `nil` if name passed to `Asciidoctor::SafeMode.value_for_name` is not recognized (#3526) * Modify default stylesheet to honor text-* roles on quote blocks +Bug Fixes:: + + * Don't leave behind empty line inside skipped preprocessor conditional (#4580) + == 2.0.22 (2024-03-08) - @mojavelinux Improvements:: diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index 2aa565ce..23000dda 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -807,6 +807,10 @@ class PreprocessorReader < Reader return line unless @process_lines if line.empty? + if @skipping + shift + return nil + end @look_ahead += 1 return line end diff --git a/test/reader_test.rb b/test/reader_test.rb index be8ccd49..28e44268 100644 --- a/test/reader_test.rb +++ b/test/reader_test.rb @@ -2232,6 +2232,19 @@ class ReaderTest < Minitest::Test 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[] @@ -2541,6 +2554,19 @@ class ReaderTest < Minitest::Test 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! |
