Skip to content

Commit

Permalink
Ensure file content is read as UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
brenogazzola committed Nov 13, 2023
1 parent 0237135 commit 0ca5f36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/propshaft/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(path, logical_path:, version: nil)
end

def content
File.binread(path)
File.binread(path).force_encoding("UTF-8")
end

def content_type
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/assets/first_path/utf-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ε
4 changes: 4 additions & 0 deletions test/propshaft/asset_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class Propshaft::AssetTest < ActiveSupport::TestCase
assert_equal asset.digest.object_id, asset.digest.object_id
end

test "content with utf-8" do
assert_equal "Ε", find_asset("utf-8.txt").content
end

private
def find_asset(logical_path)
root_path = Pathname.new("#{__dir__}/../fixtures/assets/first_path")
Expand Down

0 comments on commit 0ca5f36

Please sign in to comment.