Skip to content

Commit

Permalink
don't crash if source block with custom subs is empty and source high…
Browse files Browse the repository at this point in the history
…lighter is enabled
  • Loading branch information
mojavelinux committed Apr 10, 2023
1 parent 893fb2e commit c53a0ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co

== Unreleased

_No changes since previous release._
Bug Fixes::

* don't crash if source block with custom subs is empty and source highlighter is enabled

== 2.3.6 (2023-04-09) - @mojavelinux

Expand Down
3 changes: 2 additions & 1 deletion lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,9 @@ def convert_code node
callouts_enabled = false
end
subs[highlight_idx] = :specialcharacters
source_string = node.content || ''
# NOTE: indentation guards will be added by the source highlighter logic
source_string = expand_tabs unescape_xml (sanitize node.content, compact: false)
source_string = expand_tabs unescape_xml (sanitize source_string, compact: false) unless source_string.empty?
node.lines.replace saved_lines if saved_lines
end
else
Expand Down
14 changes: 14 additions & 0 deletions spec/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,20 @@ class Type; end
(expect attr_name_text[:font_color]).to eql '4F9FCF'
(expect (pdf.find_text '①')[0]).not_to be_nil
end

it 'should not crash if source highlighter is enabled and subs is set on empty block' do
(expect do
input = <<~'END'
[source,ruby,subs=attributes+]
----
----
END
lines = (to_pdf input, attribute_overrides: { 'source-highlighter' => 'coderay' }, analyze: :line).lines
text = (to_pdf input, attribute_overrides: { 'source-highlighter' => 'coderay' }, analyze: true).text
(expect (lines[0][:from][:y] - lines[1][:from][:y]).abs).to be < 5
(expect text).to be_empty
end).not_to raise_exception
end
end

context 'Pygments' do
Expand Down

0 comments on commit c53a0ab

Please sign in to comment.