Skip to content

Commit

Permalink
Fix .jpeg precompile issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiculescu committed Feb 11, 2023
1 parent 925fb65 commit 1e999b4
Show file tree
Hide file tree
Showing 5 changed files with 13 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

- Fix for precompile issues when multiple extensions map to the same MIME type (eg. `.jpeg` / `.jpg`). [#781](https://github.com/rails/sprockets/pull/781)

## 4.2.0

- Rack 3 compatibility. [#758](https://github.com/rails/sprockets/pull/758)
Expand Down
4 changes: 3 additions & 1 deletion lib/sprockets/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def load_from_unloaded(unloaded)
end

if type = unloaded.params[:type]
logical_path += config[:mime_types][type][:extensions].first
extensions = config[:mime_types][type][:extensions]
extension = extensions.include?(extname) ? extname : extensions.first
logical_path += extension
end

if type != file_type && !config[:transformers][file_type][type]
Expand Down
Binary file added test/fixtures/default/blue_jpeg.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/default/blue_jpg.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions test/test_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def setup
assert_raises Sprockets::ConversionError do
@env.load("file://#{fixture_path_for_uri('default/gallery.js')}?type=text/css")
end

assert asset = @env.load("file://#{fixture_path_for_uri('default/blue_jpg.jpg')}?type=image/jpeg")
assert_equal fixture_path('default/blue_jpg.jpg'), asset.filename
assert_equal 'blue_jpg.jpg', asset.logical_path

assert asset = @env.load("file://#{fixture_path_for_uri('default/blue_jpeg.jpeg')}?type=image/jpeg")
assert_equal fixture_path('default/blue_jpeg.jpeg'), asset.filename
assert_equal 'blue_jpeg.jpeg', asset.logical_path
end

test 'load outside asset' do
Expand Down

0 comments on commit 1e999b4

Please sign in to comment.