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

Fix .jpeg precompile issue #781

Merged
merged 1 commit into from
Mar 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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