Skip to content
Merged
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
3 changes: 1 addition & 2 deletions lib/sprockets/encoding_utils.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true
require 'base64'
require 'stringio'
require 'zlib'

Expand Down Expand Up @@ -71,7 +70,7 @@ def gzip(str)
#
# Returns a encoded String
def base64(str)
Base64.strict_encode64(str)
[str].pack("m0")
end


Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/asset/sprite.css.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
*/

<%
require 'base64'
path = File.expand_path("../POW.png", __FILE__)
data = Base64.encode64(File.open(path, "rb") { |f| f.read })
data = [File.open(path, "rb") { |f| f.read }].pack('m')
%>
.pow {
background: url(data:image/png;base64,<%= data %>) no-repeat;
Expand Down
10 changes: 3 additions & 7 deletions test/test_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def setup
test "extend context" do
@env.context_class.class_eval do
def datauri(path)
require 'base64'
Base64.encode64(File.open(path, "rb") { |f| f.read })
[File.open(path, "rb") { |f| f.read }].pack('m')
end
end

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

require 'base64'
DataUriProcessor = proc do |input|
env = input[:environment]
data = input[:data]
data.gsub(/url\(\"(.+?)\"\)/) do
uri, _ = env.resolve($1)
path, _ = env.parse_asset_uri(uri)
data = Base64.encode64(File.open(path, "rb") { |f| f.read })
data = [File.open(path, "rb") { |f| f.read }].pack('m')
"url(data:image/png;base64,#{data})"
end
end
Expand All @@ -111,14 +109,12 @@ def setup
end

test "block custom processor" do
require 'base64'

@env.register_preprocessor 'text/css' do |input|
env = input[:environment]
input[:data].gsub(/url\(\"(.+?)\"\)/) do
uri, _ = env.resolve($1)
path, _ = env.parse_asset_uri(uri)
data = Base64.encode64(File.open(path, "rb") { |f| f.read })
data = [File.open(path, "rb") { |f| f.read }].pack('m')
"url(data:image/png;base64,#{data})"
end
end
Expand Down
Loading