8000 Integration with open-uri-cached does not work with Ruby 3.1 · Issue #4227 · asciidoctor/asciidoctor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Integration with open-uri-cached does not work with Ruby 3.1 #4227
Closed
@mojavelinux

Description

@mojavelinux

Ruby 3.1 changed the behavior of YAML.load to match YAML.safe_load. The open-uri/cached gem uses YAML.load to load data that includes tags, which are classified as an unsafe feature. As a result, this gem cannot load its own cached data and thus fails to retrieve the image from the cache. Asciidoctor will need to patch the gem so the integration will work when using Ruby 3.1.

Here's the patch to apply:

def patch_open_uri_cached
  return unless (::YAML.respond_to? :unsafe_load) && !(::OpenURI::Cache.const_defined? :YAML, false)
  ::OpenURI::Cache.const_set :YAML, (::Module.new do
    define_singleton_method :dump, &(::YAML.method :dump)
    define_singleton_method :load, &(::YAML.method :unsafe_load)
  end)
end

This patch injects an unsafe YAML implementation into the scope of the gem so it continues to work as it did before.

Metadata

Metadata

Assignees

Labels

bugIssues describing a malfunction that needs to be fixed to comply with the expected behaviorv2.0.17Issues resolved in the 2.0.17 release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0