Asciidoctor: Failure when inlining 0 byte SVG

Created on 30 Apr 2020  路  4Comments  路  Source: asciidoctor/asciidoctor

Coming from asciidoctor/asciidoctor-diagram#280 as suggested by @mojavelinux. I noticed that the HTML5 backed fails when it tries to inline a 0 bytes SVG.

I believe the tool should instead report a warning that the file size is 0.

_I noticed this issue due to a bogus SVG file created by Asciidoctor Diagram._


When running asciidoctor on file with a plantuml diagram I encountered the following issue. (Removing the opts="inline" solves prevent the error, but does not match what I need.)
This diagram worked well until now, and I don't know for sure what happend, especially since I don't know much about ruby.

asciidoctor --trace --verbose --base-dir=. --backend=html5 --require asciidoctor-diagram --attribute=icons=font --attribute sectlinks --attribute sectanchors --attribute diagram-svg-type=inline plantuml.smoketest.adoc
[plantuml,"activity-diagram-example",format="svg",opts="inline"]
.Activity diagram
----
@startuml

start
if (condition A) then (yes)
  :Text 1a;
  :Text 1b/
elseif (condition B) then (yes)
  :Text 2|
  stop
elseif (condition C) then (yes)
  :Text 3<
elseif (condition D) then (yes)
  :Text 4>
else (nothing)
  :Text else}
  note right
    This note is on several
    //lines// and can
    contain <b>HTML</b>
    ====
    * Calling the method ""foo()"" is prohibited
  end note
endif
stop

@enduml
----

trace

Traceback (most recent call last):
        28: from /usr/local/Cellar/asciidoctor/2.0.10_1/libexec/bin/asciidoctor:23:in `<main>'
        27: from /usr/local/Cellar/asciidoctor/2.0.10_1/libexec/bin/asciidoctor:23:in `load'
        26: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/bin/asciidoctor:15:in `<top (required)>'
        25: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/cli/invoker.rb:111:in `invoke!'
        24: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/cli/invoker.rb:111:in `each'
        23: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/cli/invoker.rb:128:in `block in invoke!'
        22: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/convert.rb:183:in `convert_file'
        21: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/convert.rb:183:in `open'
        20: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/convert.rb:183:in `block in convert_file'
        19: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/convert.rb:118:in `convert'
        18: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/document.rb:951:in `convert'
        17: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:84:in `convert'
        16: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:227:in `convert_document'
        15: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/document.rb:1020:in `content'
        14: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:84:in `content'
        13: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:84:in `map'
        12: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:84:in `block in content'
        11: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:75:in `convert'
        10: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:54:in `convert'
         9: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:416:in `convert_section'
         8: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:84:in `content'
         7: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:84:in `map'
         6: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:84:in `block in content'
         5: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb:75:in `convert'
         4: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:65:in `convert'
         3: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:624:in `convert_image'
         2: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:1259:in `read_svg_contents'
         1: from /Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:1259:in `each'
/Library/Ruby/Gems/2.6.0/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb:1261:in `block in read_svg_contents': undefined method `[]' for nil:NilClass (NoMethodError)

gem query --local

*** LOCAL GEMS ***

asciidoctor (2.0.10)
asciidoctor-diagram (2.0.2)
asciidoctor-html5s (0.5.0, 0.4.1)
bigdecimal (2.0.0, default: 1.4.1)
bundler (2.1.4, default: 1.17.2)
CFPropertyList (3.0.2, 2.3.6)
cmath (default: 1.0.0)
csv (3.1.2, default: 3.0.9)
date (3.0.0, default: 2.0.0)
dbm (1.1.0, default: 1.0.0)
did_you_mean (1.4.0, 1.3.0)
e2mmap (default: 0.1.0)
etc (1.1.0, default: 1.0.1)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (1.4.1, default: 1.1.0)
forwardable (1.3.1, default: 1.2.0)
hpricot (0.8.6)
io-console (0.5.6, 0.5.5, 0.5.4, default: 0.4.7)
ipaddr (default: 1.2.2)
irb (1.2.3, 1.2.1, default: 1.0.0)
json (2.3.0, default: 2.1.0)
libxml-ruby (3.1.0)
logger (1.4.2, default: 1.3.0)
matrix (default: 0.1.0)
mini_portile2 (2.5.0, 2.4.0)
minitest (5.14.0, 5.11.3)
mustache (1.1.1)
mutex_m (default: 0.1.0)
net-telnet (0.2.0)
nokogiri (1.10.9, 1.10.8, 1.10.7, 1.10.1)
openssl (default: 2.1.2)
ostruct (default: 0.1.0)
power_assert (1.2.0, 1.1.7, 1.1.6, 1.1.5, 1.1.3)
prime (default: 0.1.0)
psych (default: 3.1.0)
rake (13.0.1, 12.3.2)
rdiscount (2.2.0.1)
rdoc (6.2.1, default: 6.1.0)
reline (0.1.4, 0.1.3, 0.1.2)
rexml (3.2.4, 3.2.3, default: 3.1.9)
ronn (0.7.3)
rss (0.2.9, 0.2.8, default: 0.2.7)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
shell (0.8.0, default: 0.7)
sqlite3 (1.4.2, 1.3.13)
stringio (0.1.0, default: 0.0.2)
strscan (1.0.3, default: 1.0.0)
sync (default: 0.5.0)
test-unit (3.3.5, 3.2.9)
thread_safe (0.3.6)
thwait (default: 0.1.0)
tracer (default: 0.1.0)
webrick (1.6.0, default: 1.4.2)
xmlrpc (0.3.0)
zlib (1.1.0, default: 1.0.0)


$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.4
BuildVersion:   19E287
bug v2.0.11

Most helpful comment

Let's try to get this into 2.0.11.

All 4 comments

For reference, here's the code:
https://github.com/asciidoctor/asciidoctor/blob/9302213ea29e2efa75a7b3f9124ce4bbcd738174/lib/asciidoctor/converter/html5.rb#L1261

So we should check that (svg.match SvgStartTagRx) is not nil before calling [0].
In addition, we could eagerly stop the processing as soon as we know that svg is empty.

Let's try to get this into 2.0.11.

@mojavelinux Should we include this request: "I believe the tool should instead report a warning that the file size is 0." ? If we do I think we should add this warning in read_contents. We could add an option if we want to make it optional warn_on_empty (similar to warn_on_failure).

Tasks

  • [ ] Check that svg is not empty, if that's the case stop the processing and return the value
  • [ ] Check that the regular expression SvgStartTagRx matches something otherwise? (it indicates that the SVG is malformed, so we could also issue a warning or silently proceed)

Here's a minimal case that reproduces this issue (assuming empty.svg is an empty file):

image::empty.svg[,100,opts=inline]
Was this page helpful?
0 / 5 - 0 ratings