asciidoctor-pdf: Image lookup does not work if both `pdf-themesdir` and `pdf-theme` are set to distinct `uri:classloader:` paths

Can there possibly be some regression @mojavelinux? It seems despite me specifying a pdf-themesdir (as a ~uri:classpath~ uri:classloader), the background-image is being prefixed with a local path. This code triggers

Dec 29, 2022 7:50:30 PM uri:classloader:/gems/asciidoctor-pdf-2.3.4/lib/asciidoctor/pdf/converter.rb resolve_background_image WARNING: title page background image not found or readable: C:/Users/SEBAST~1/AppData/Local/Temp/ort-PdfTemplateReporter-asciidoc8842694912548045678/uri:classloader:/images/ort.png

Hmm, or does pdf-themesdir (in contrast to pdf-fontsdir) not support ~uri:classpath~ uri:classloader? At least it’s not explicitly mentioned in the docs.

_Originally posted by @sschuberth in https://github.com/asciidoctor/asciidoctor-pdf/issues/1829#issuecomment-1367529272_

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 39 (22 by maintainers)

Commits related to this issue

Most upvoted comments

@sschuberth The workaround is included in the 2.3.6 release. I’ll probably keep it in the 2.3.x release line, but remove it from main once we can confirm that JRuby handles the logic.

@mojavelinux I have not stepped through this yet but that is baffling to me too. There are specs to test absolute_path? but because I forgot this should have added our value-added logic for URIs it just calls the most obvious methods (and the normal ruby specs for this pass). When I figure this out we will definitely add tests for this and probably audit what else is calling the methods which made this return true.

I don’t have time to track this down right now. But I am trying to get a patch into Asciidoctor PDF to work around it since this has the potential for causing a lot of problems for people upgrading.

I found the exact change. Consider the following Ruby script:

require 'pathname'

p (::Pathname.new 'uri:classloader:/pdf-themes/logo.png').absolute?
if File.respond_to? :absolute_path?
  p File.absolute_path? 'uri:classloader:/pdf-themes/logo.png'
end

Here are the results with different versions of JRuby:

  • JRuby 9.4.2.0 - true, false
  • JRuby 9.3.7.0 - true
  • JRuby 9.1.17.0 - true

What happened is that JRuby 9.4.2.0 implemented File.absolute_path? for the first time, but its return value does not match Pathname#absolute?. That breaks the following assumption in Asciidoctor PDF: https://github.com/asciidoctor/asciidoctor-pdf/blob/main/lib/asciidoctor/pdf/ext/core/file.rb

That means we can’t rely on it. I can put in a workaround in the meantime, but this really strikes me as a bug in JRuby. I don’t see why these two return values should be different.