Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions data_uri.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
Gem::Specification.new do |s|
s.name = "data_uri"
s.version = "0.0.3"
# Master's gemspec was left at 0.0.3 though RubyGems published 0.1.0 from the
# identical source. Track 0.1.0 so this fork is a drop-in for the pinned release.
s.version = "0.1.0"
s.author = "Donald Ball"
s.email = "donald.ball@gmail.com"
s.homepage = "http://github.com/dball/data_uri"
s.description = "URI class for parsing data URIs"
s.summary = "A URI class for parsing data URIs as per RFC2397"

s.platform = Gem::Platform::RUBY
s.has_rdoc = true
# s.has_rdoc was removed from RubyGems::Specification; dropping it avoids a
# NoMethodError when the gemspec is evaluated on modern RubyGems.
s.extra_rdoc_files = ["README.rdoc"]

s.require_path = 'lib'
Expand Down
13 changes: 11 additions & 2 deletions lib/data_uri/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def initialize(*args)
raise URI::InvalidURIError.new('Invalid data URI')
end
@data = @data[1 .. -1]
@data = base64 ? Base64.decode64(@data) : URI.decode(@data)
# URI.decode was removed in Ruby 3.0; use the default parser's #unescape,
# which performs the same RFC-2396 percent-decoding the data URI body needs.
@data = base64 ? Base64.decode64(@data) : URI::DEFAULT_PARSER.unescape(@data)
if @data.respond_to?(:force_encoding) && charset = @mime_params['charset']
@data.force_encoding(charset)
end
Expand All @@ -61,6 +63,13 @@ def self.build(arg)
end
end

@@schemes['DATA'] = Data
# Ruby 3.x removed the URI @@schemes class variable. Register via the public
# API (URI.register_scheme, available since Ruby 2.7) instead of mutating the
# internal @@schemes hash directly.
if URI.respond_to?(:register_scheme)
URI.register_scheme('DATA', Data)
else
@@schemes['DATA'] = Data
end

end