Skip to content

Commit

Permalink
Ensure asset source is utf-8 encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
AyoubEssrifi committed Nov 13, 2023
1 parent 5b040f3 commit 079c1ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md

- Ensure asset source is always UTF-8 encoded.

## 4.2.1

- Fix for precompile issues when multiple extensions map to the same MIME type (eg. `.jpeg` / `.jpg`). [#781](https://github.com/rails/sprockets/pull/781)
Expand Down
3 changes: 2 additions & 1 deletion lib/sprockets/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def source
@source
else
# File is read everytime to avoid memory bloat of large binary files
File.binread(filename)
file = File.binread(filename)
file.encoding == Encoding::BINARY ? file : file.force_encoding('utf-8')
end
end

Expand Down

0 comments on commit 079c1ac

Please sign in to comment.