summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2023-04-10 03:24:55 -0600
committerDan Allen <dan.j.allen@gmail.com>2023-04-13 00:27:40 -0600
commitfc240fd834eb812a64cd7d1ae725cb6425082627 (patch)
tree9c8c5eae2752f32a3ca5d44c835bb92b9e3cca56
parent464f20d92b82e8c8fb0a95069f84188de1cf3769 (diff)
add workaround for JRuby on Windows when value of imagesdir attribute is absolute and contains non-ASCII characters
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/ext/core/file.rb6
-rw-r--r--spec/fixtures/测试/square.pngbin0 -> 157 bytes
-rw-r--r--spec/image_spec.rb18
4 files changed, 25 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 024ccab7..8b50c78a 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -10,6 +10,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
Bug Fixes::
* don't crash if source block with custom subs is empty and source highlighter is enabled
+* add workaround for JRuby on Windows when value of `imagesdir` attribute is absolute and contains non-ASCII characters
== 2.3.6 (2023-04-09) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/ext/core/file.rb b/lib/asciidoctor/pdf/ext/core/file.rb
index 9f46397c..4fe96787 100644
--- a/lib/asciidoctor/pdf/ext/core/file.rb
+++ b/lib/asciidoctor/pdf/ext/core/file.rb
@@ -1,6 +1,12 @@
# frozen_string_literal: true
File.singleton_class.prepend (Module.new do
+ # NOTE: see https://github.com/jruby/jruby/issues/7750
+ def absolute_path path, dir = nil
+ return super unless dir && !(absolute_path? path)
+ super File.join dir, path
+ end
+
# NOTE: JRuby < 9.4 doesn't implement this method; JRuby 9.4 implements it incorrectly
def absolute_path? path
(::Pathname.new path).absolute? && !(%r/\A[[:alpha:]][[:alnum:]\-+]*:\/\/\S/.match? path)
diff --git a/spec/fixtures/测试/square.png b/spec/fixtures/测试/square.png
new file mode 100644
index 00000000..978fd0a2
--- /dev/null
+++ b/spec/fixtures/测试/square.png
Binary files differ
diff --git a/spec/image_spec.rb b/spec/image_spec.rb
index e67a4d31..1a187fd0 100644
--- a/spec/image_spec.rb
+++ b/spec/image_spec.rb
@@ -136,6 +136,24 @@ describe 'Asciidoctor::PDF::Converter - Image' do
(expect to_file).to visually_match 'image-wolpertinger.pdf'
end
+ it 'should resolve target of block image if imagesdir is absolute directory with non-ASCII characters' do
+ pdf = to_pdf <<~'EOS', analyze: :image, attribute_overrides: { 'imagesdir' => (File.join fixtures_dir, %(\u6d4b\u8bd5)) }
+ image::square.png[pdfwidth=1in]
+ EOS
+
+ (expect pdf.images).to have_size 1
+ end
+
+ it 'should resolve target of block image if imagesdir is not set and pwd contains non-ASCII characters' do
+ Dir.chdir (File.join fixtures_dir, %(\u6d4b\u8bd5)) do
+ pdf = to_pdf <<~'EOS', analyze: :image
+ image::square.png[pdfwidth=1in]
+ EOS
+
+ (expect pdf.images).to have_size 1
+ end
+ end
+
it 'should replace block image with alt text if image is missing' do
(expect do
pdf = to_pdf 'image::no-such-image.png[Missing Image]', analyze: true