summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2024-03-08 01:28:32 -0700
committerDan Allen <dan.j.allen@gmail.com>2024-03-08 01:29:47 -0700
commita25931bf6bcd90edd795f481192b9b74b9e75d87 (patch)
tree94c63af90287623aca1b2b296b5753ac0ce05c71
parent8a64f8cafd9471c046deb7a939b700e5701cfd99 (diff)
eradicate the use of the base64 library
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--Gemfile1
-rw-r--r--lib/asciidoctor/pdf/converter.rb14
-rw-r--r--lib/asciidoctor/pdf/ext/asciidoctor/image.rb5
4 files changed, 11 insertions, 10 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 53d31694..9ea80834 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -14,6 +14,7 @@ Improvements::
Bug Fixes::
* propagate source location to table cell for description in horizontal dlist so it is included in truncation warning message (#2502)
+* eradicate use of the base64 library to fix waarning about base64 gem when using Ruby >= 3.3
* upgrade prawn-svg to 0.34 to fix warning about base64 gem when using Ruby >= 3.3; apply additional patch to fix bug in prawn-svg
Build / Infrastructure::
diff --git a/Gemfile b/Gemfile
index 3f29eaad..e46a41e1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,7 +8,6 @@ gemspec
gem 'asciidoctor', ENV['ASCIIDOCTOR_VERSION'], require: false if ENV.key? 'ASCIIDOCTOR_VERSION'
gem 'asciidoctor-diagram', ENV['ASCIIDOCTOR_DIAGRAM_VERSION'], require: false if ENV.key? 'ASCIIDOCTOR_DIAGRAM_VERSION'
gem 'asciidoctor-kroki', ENV['ASCIIDOCTOR_KROKI_VERSION'], require: false if ENV.key? 'ASCIIDOCTOR_KROKI_VERSION'
-gem 'base64', require: false if (Gem::Version.new RUBY_VERSION) >= (Gem::Version.new '3.3.0') # required until asciidoctor 2.0.22 is out
gem 'coderay', '~> 1.1.0', require: false
gem 'open-uri-cached', '~> 1.0.0', require: false
gem 'prawn-gmagick', ENV['PRAWN_GMAGICK_VERSION'], require: false if (ENV.key? 'PRAWN_GMAGICK_VERSION') && RUBY_ENGINE == 'ruby'
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 89ff9a4c..791fd1cc 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -1721,7 +1721,7 @@ module Asciidoctor
if image_format == 'gif' && !(defined? ::GMagick::Image)
log :warn, %(GIF image format not supported. Install the prawn-gmagick gem or convert #{target} to PNG.)
image_path = nil
- elsif ::Base64 === target
+ elsif ::Asciidoctor::Image::Base64Encoded === target
image_path = target
elsif (image_path = resolve_image_path node, target, image_format, (opts.fetch :relative_to_imagesdir, true))
if image_format == 'pdf'
@@ -1790,8 +1790,8 @@ module Asciidoctor
rendered_h = rendered_w = nil
span_page_width_if align_to_page do
if image_format == 'svg'
- if ::Base64 === image_path
- svg_data = ::Base64.decode64 image_path
+ if ::Asciidoctor::Image::Base64Encoded === image_path
+ svg_data = image_path.unpack1 'm'
file_request_root = false
else
svg_data = ::File.read image_path, mode: 'r:UTF-8'
@@ -1842,8 +1842,8 @@ module Asciidoctor
else
# FIXME: this code really needs to be better organized!
# NOTE: use low-level API to access intrinsic dimensions; build_image_object caches image data previously loaded
- image_obj, image_info = ::Base64 === image_path ?
- ::StringIO.open((::Base64.decode64 image_path), 'rb') {|fd| build_image_object fd } :
+ image_obj, image_info = ::Asciidoctor::Image::Base64Encoded === image_path ?
+ ::StringIO.open((image_path.unpack1 'm'), 'rb') {|fd| build_image_object fd } :
::File.open(image_path, 'rb') {|fd| build_image_object fd }
actual_w = to_pt image_info.width, :px
width = actual_w * scale if scale
@@ -4313,11 +4313,11 @@ module Asciidoctor
end
@tmp_files ||= {}
# NOTE: base64 logic currently used for inline images
- if ::Base64 === image_path
+ if ::Asciidoctor::Image::Base64Encoded === image_path
return @tmp_files[image_path] if @tmp_files.key? image_path
tmp_image = ::Tempfile.create %W(image- .#{image_format})
tmp_image.binmode unless image_format == 'svg'
- tmp_image.write ::Base64.decode64 image_path
+ tmp_image.write image_path.unpack1 'm'
tmp_image.close
@tmp_files[image_path] = tmp_image.path
# NOTE: this will catch a classloader resource path on JRuby (e.g., uri:classloader:/path/to/image)
diff --git a/lib/asciidoctor/pdf/ext/asciidoctor/image.rb b/lib/asciidoctor/pdf/ext/asciidoctor/image.rb
index 94988c87..d4a67109 100644
--- a/lib/asciidoctor/pdf/ext/asciidoctor/image.rb
+++ b/lib/asciidoctor/pdf/ext/asciidoctor/image.rb
@@ -2,6 +2,7 @@
module Asciidoctor
module Image
+ Base64Encoded = ::Module.new
DataUriRx = %r(^data:image/(?<fmt>png|jpe?g|gif|pdf|bmp|tiff|svg\+xml);base64,(?<data>.*)$)
FormatAliases = { 'jpg' => 'jpeg', 'svg+xml' => 'svg' }
@@ -11,7 +12,7 @@ module Asciidoctor
def self.target_and_format image_path, attributes = nil
if (image_path.start_with? 'data:') && (m = DataUriRx.match image_path)
- [(m[:data].extend ::Base64), (FormatAliases.fetch m[:fmt], m[:fmt])]
+ [(m[:data].extend Base64Encoded), (FormatAliases.fetch m[:fmt], m[:fmt])]
else
[image_path, attributes&.[]('format') || ((ext = ::File.extname image_path).downcase.slice 1, ext.length)]
end
@@ -20,7 +21,7 @@ module Asciidoctor
def target_and_format
image_path = inline? ? target : (attr 'target')
if (image_path.start_with? 'data:') && (m = DataUriRx.match image_path)
- [(m[:data].extend ::Base64), (FormatAliases.fetch m[:fmt], m[:fmt])]
+ [(m[:data].extend Base64Encoded), (FormatAliases.fetch m[:fmt], m[:fmt])]
else
[image_path, (attr 'format', nil, false) || ((ext = ::File.extname image_path).downcase.slice 1, ext.length)]
end