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

JPEG extension is now forced to JPG #304

Closed
virgoproz opened this issue Jan 5, 2016 · 11 comments · Fixed by plastmastick/TestGuru_Thinknetica#20 or rails/sprockets#781
Closed

JPEG extension is now forced to JPG #304

virgoproz opened this issue Jan 5, 2016 · 11 comments · Fixed by plastmastick/TestGuru_Thinknetica#20 or rails/sprockets#781

Comments

@virgoproz
Copy link

Until 2.3.3, it was ok to have files JPEG using .jpeg or .jpg as extension.

From 3.0, JPEG are automatically converted to .jpg (both with actual precompilation and sandbox precompile errors). If you have something like image_tag('image.jpeg'), it breaks with the AssestNotPrecompiled error. Renaming the file to image.jpg will fix it.

Not a big deal for developers, refactoring filenames not a big ask :), just worth noting if this was not intentional.

@jdleesmiller
Copy link

Perhaps this is related to #246.

In case this saves someone else some time and head-scratching, I was getting

ActionView::Template::Error: Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( resources/foo.jpeg )` to `config/initializers/assets.rb` and restart your server

from tests when rendering a view with a image_tag 'resources/foo.jpeg' helper. The problem went away when the file was renamed from .jpeg to .jpg. Downgrading to 2.3.3 also solved the problem.

It's also worth noting that if you follow the advice in the warning and add the resource to your precompile list, that does not help.

@octoxan
Copy link

octoxan commented Sep 13, 2019

Lost a few hours of my life to this issue lol

floehopper added a commit to freerange/site that referenced this issue Sep 28, 2019
It turns out that image_tag turns a jpeg extension in the path into a
jpg extension [1], but sprockets doesn't change the actual image file
name, so you get a Sprockets::Rails::Helper::AssetNotFound exception.
Hopefully this should fix the problem.

[1]: rails/sprockets-rails#304
@schneems
Copy link
Member

schneems commented Sep 15, 2020

just worth noting if this was not intentional.

I don't think it was intentional. Does anyone have a super small https://www.codetriage.com/example_app that shows this issue?

david-mears pushed a commit to david-mears/game_of_cups that referenced this issue Sep 16, 2020
jpeg files are not happy in production environment

See rails/sprockets-rails#304
@david-mears
Copy link

david-mears commented Sep 16, 2020

@schneems I came across this issue in my hobby app today. I have stripped out everything apart from what is needed to demonstrate the issue, and I've put it in this repo:

https://github.com/david-mears/jpeg-issue-demo/

I deployed it to https://sheltered-beach-99525.herokuapp.com/, which is up at the time of writing. Heroku hobby apps sleep when they haven't been touched for 30 minutes, so give it a minute to wake up.

I don't fully understand CodeTriage, so I'm not sure if I managed to submit it there.

Through trial and error, I discovered that only files ending .jpeg cause errors such as the below from my heroku logs:

ActionView::Template::Error (The asset "cups/goldcup.jpeg" is not present in the asset pipeline.
...
ActionView::Template::Error (The asset "cups/cup 8.jpeg" is not present in the asset pipeline.
...
ActionView::Template::Error (The asset "cups/chalice5.jpeg" is not present in the asset pipeline.

The bug can be 'fixed' either by renaming jpegs to jpgs, or by setting config.assets.compile = true
in production.rb.

@schneems
Copy link
Member

I don't fully understand CodeTriage, so I'm not sure if I managed to submit it there.

The link I provided has instructions on making an example app it looks like github didn't expand the link.

or by setting config.assets.compile = true in production.rb.

To note: this will have performance issues and also opened a directory traversal security issue in an older version of sprockets.

Thanks for the app!

david-mears pushed a commit to david-mears/game_of_cups that referenced this issue Sep 16, 2020
jpeg files are not happy in production environment

See rails/sprockets-rails#304
@jrochkind
Copy link

jrochkind commented May 18, 2021

As reported above, for me breaks in production, but works fine in development.

If you have an asset ending in jpeg, and reference it with eg Rails image_tag("something.jpeg") -- works fine in development, raises Sprockets::Rails::Helper::AssetNotFound in production.

  • sprockets-rails 3.2.2
  • sprockets 4.0.2
  • rails 6.1.3.2

This is terribly confusing, not really documented anywhere as far as I know, and I just spent a few hours figuring it out -- and I am a very experienced Rails user.

It would be acceptable (if not ideal) if it failed in both development and production, if jpeg was just not allowed as a suffix for some reason. But working in development and failing in production is pretty unforgiveable. It at least needs to be very clearly documented.

That this is a long-running bug is making me question Sprockets viability.

@ajaleelp
Copy link

Took me a while to find this out! Anybody who can point me to the reason behind this? And totally agree with @jrochkind , it should atleast be warned about - especially given that it is not the same behaviour in development.

@pooriajr
Copy link

pooriajr commented Dec 3, 2022

This issue drove me insane today 😅

@unRARed
Copy link

unRARed commented Jan 10, 2023

Got me, too today. We just migrated away from Webpacker to jsbundling-rails with webpack and Sprockets. Per @jrochkind, at minimum the development experience should mirror production. Nothing worse than everything working great locally (where it's safe to fail) only to have it fail on production.

ghiculescu added a commit to ghiculescu/sprockets that referenced this issue Feb 10, 2023
@ghiculescu
Copy link
Member

I think rails/sprockets#781 will fix this issue.

ghiculescu added a commit to ghiculescu/sprockets that referenced this issue Feb 11, 2023
ghiculescu added a commit to ghiculescu/sprockets that referenced this issue Feb 11, 2023
@brandondrew
Copy link

A bug from January 2016 is still biting people today?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet