Skip to content

Commit c696d6b

Browse files
authored
Asciidoctor: Be careful about bad callouts (#602)
Stops the callout image copying code from attempting to copy the images for bad callouts and crashing.
1 parent d619223 commit c696d6b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

resources/asciidoctor/lib/copy_images/extension.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def process_block(block)
3333
callout_extension = block.document.attr 'copy-callout-images'
3434
if callout_extension
3535
if block.parent && block.parent.context == :colist
36-
block.attr('coids').scan(/CO(?:\d+)-(\d+)/) {
36+
coids = block.attr('coids')
37+
return unless coids
38+
39+
coids.scan(/CO(?:\d+)-(\d+)/) {
3740
copy_image block, "images/icons/callouts/#{$1}.#{callout_extension}"
3841
}
3942
return

resources/asciidoctor/spec/copy_images_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,28 @@ def copy_attributes(copied)
358358
])
359359
end
360360

361+
it "doesn't blow up when the callout can't be found" do
362+
copied = []
363+
attributes = copy_attributes copied
364+
attributes['copy-callout-images'] = 'png'
365+
input = <<~ASCIIDOC
366+
== Example
367+
----
368+
foo <1>
369+
----
370+
<1> words
371+
<2> doesn't get an id
372+
ASCIIDOC
373+
expected_warnings = <<~WARNINGS
374+
WARN: <stdin>: line 6: no callout found for <2>
375+
INFO: <stdin>: line 5: copying #{spec_dir}/resources/copy_images/images/icons/callouts/1.png
376+
WARNINGS
377+
convert input, attributes, eq(expected_warnings.strip)
378+
expect(copied).to eq([
379+
["images/icons/callouts/1.png", "#{spec_dir}/resources/copy_images/images/icons/callouts/1.png"],
380+
])
381+
end
382+
361383
it "doesn't copy callout images if the extension isn't set" do
362384
copied = []
363385
attributes = copy_attributes copied

0 commit comments

Comments
 (0)