Skip to content

Commit b8eaeef

Browse files
committed
Drop base64 gem from dependency
This following warning is shown in test. ``` /Users/ryunosuke.sato/src/github.com/rails/sprockets/lib/sprockets/mime.rb:2: warning: base64 was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.4.0. You can add base64 to your Gemfile or gemspec to silence this warning. ``` Instead of adding base64 to dependency, the usage of `Base64#strict_encode64` and `Base64#encode64` have replaced with `Array#pack`.
1 parent 3bea557 commit b8eaeef

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

lib/sprockets/encoding_utils.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
require 'base64'
32
require 'stringio'
43
require 'zlib'
54

@@ -71,7 +70,7 @@ def gzip(str)
7170
#
7271
# Returns a encoded String
7372
def base64(str)
74-
Base64.strict_encode64(str)
73+
[str].pack("m0")
7574
end
7675

7776

test/fixtures/asset/sprite.css.erb

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
*/
44

55
<%
6-
require 'base64'
76
path = File.expand_path("../POW.png", __FILE__)
8-
data = Base64.encode64(File.open(path, "rb") { |f| f.read })
7+
data = [File.open(path, "rb") { |f| f.read }].pack('m')
98
%>
109
.pow {
1110
background: url(data:image/png;base64,<%= data %>) no-repeat;

test/test_context.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def setup
4747
test "extend context" do
4848
@env.context_class.class_eval do
4949
def datauri(path)
50-
require 'base64'
51-
Base64.encode64(File.open(path, "rb") { |f| f.read })
50+
[File.open(path, "rb") { |f| f.read }].pack('m')
5251
end
5352
end
5453

@@ -89,14 +88,13 @@ def setup
8988
assert_equal "var Foo = {};\n\nvar Bar = {};\n", @env['application.js'].to_s
9089
end
9190

92-
require 'base64'
9391
DataUriProcessor = proc do |input|
9492
env = input[:environment]
9593
data = input[:data]
9694
data.gsub(/url\(\"(.+?)\"\)/) do
9795
uri, _ = env.resolve($1)
9896
path, _ = env.parse_asset_uri(uri)
99-
data = Base64.encode64(File.open(path, "rb") { |f| f.read })
97+
data = [File.open(path, "rb") { |f| f.read }].pack('m')
10098
"url(data:image/png;base64,#{data})"
10199
end
102100
end
@@ -111,14 +109,12 @@ def setup
111109
end
112110

113111
test "block custom processor" do
114-
require 'base64'
115-
116112
@env.register_preprocessor 'text/css' do |input|
117113
env = input[:environment]
118114
input[:data].gsub(/url\(\"(.+?)\"\)/) do
119115
uri, _ = env.resolve($1)
120116
path, _ = env.parse_asset_uri(uri)
121-
data = Base64.encode64(File.open(path, "rb") { |f| f.read })
117+
data = [File.open(path, "rb") { |f| f.read }].pack('m')
122118
"url(data:image/png;base64,#{data})"
123119
end
124120
end

0 commit comments

Comments
 (0)