diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2023-04-10 01:02:49 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2023-04-10 01:04:17 -0600 |
| commit | c53a0ab939bfbca4b3165a047e86e60c12bd5736 (patch) | |
| tree | 362da4d6e800fe652d42af7e1a0cb4fd96f62465 | |
| parent | 893fb2ef8b6917a5b7f6dbc04df7233855541b8c (diff) | |
don't crash if source block with custom subs is empty and source highlighter is enabled
| -rw-r--r-- | CHANGELOG.adoc | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 3 | ||||
| -rw-r--r-- | spec/source_spec.rb | 14 |
3 files changed, 19 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 82c98457..024ccab7 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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 diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 767725aa..c04a13d4 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -1079,8 +1079,9 @@ module Asciidoctor 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 diff --git a/spec/source_spec.rb b/spec/source_spec.rb index f1014ca8..1140c23a 100644 --- a/spec/source_spec.rb +++ b/spec/source_spec.rb @@ -1225,6 +1225,20 @@ describe 'Asciidoctor::PDF::Converter - Source' do (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 |
