Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to allow digest algorithm patching. #229

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion lib/propshaft/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def length
end

def digest
@digest ||= Digest::SHA1.hexdigest("#{content_with_compile_references}#{load_path.version}").first(8)
@digest ||= perform_digest("#{content_with_compile_references}#{load_path.version}")
end

def digested_path
Expand All @@ -57,4 +57,8 @@ def content_with_compile_references
def already_digested?
logical_path.to_s =~ /-([0-9a-zA-Z_-]{7,128})\.digested/
end

def perform_digest(text)
Digest::SHA1.hexdigest(text).first(8)
end
end
13 changes: 13 additions & 0 deletions test/propshaft/asset_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ class Propshaft::AssetTest < ActiveSupport::TestCase
assert_equal "f2e1ec14", find_asset("one.txt").digest
end

test "digest override" do
original_digest = ::Propshaft::Asset.instance_method(:perform_digest)
module ::Propshaft
class Asset
def perform_digest(text)
Digest::SHA1.hexdigest(text).first(10)
end
end
end
assert_equal 10, find_asset("one.txt").digest.size
::Propshaft::Asset.define_method(:perform_digest, original_digest)
end

test "fresh" do
assert find_asset("one.txt").fresh?("f2e1ec14")
assert_not find_asset("one.txt").fresh?("e206c34f")
Expand Down
Loading