Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The ImageStyleDownloadController did not resolve correctly the name of the source image, when the Convert effect was added to a style.
What are the steps required to reproduce the bug?
- Add image style with a convert effect to jpg
- Upload an png image to the public files root directoryand call the style url
What behavior were you expecting?
See a jpg image
What happened instead?
See a 404 page
Comment | File | Size | Author |
---|---|---|---|
#66 | 2630230.patch | 5.54 KB | eiriksm |
#56 | fix-convert-image-effect-2630230-56.patch | 5.54 KB | ayushmishra206 |
#56 | interdiff_49-56.patch | 976 bytes | ayushmishra206 |
#51 | fix-convert-image-effect-2630230-49.patch | 5.55 KB | vakulrai |
#48 | interdiff-2630230-45-48.txt | 1.35 KB | msuthars |
Comments
Comment #2
chr.fritschComment #3
chr.fritschThis only occurs if the source image is in the root file folder
Comment #4
chr.fritschPing
Comment #5
mondrakeSo this is an edge case, right? I think this needs to be reflected in the IS, and we definitely need a test to show the bug.
Comment #10
merauluka CreditAttribution: merauluka at Mediacurrent commentedI don't know if this can truly be considered an edge case. There are plenty of sites that will drop a lot of their file uploads directly into the public file folder instead of organizing them into subfolders. The issue is that the default PHP function
pathinfo
strips the trailing slashes from the "dirname" which breaks any images being converted to a different image type that are stored in the root public folder.Comment #12
mikelutzThis is still an issue, i'm rerolling this patch against 8.5. Still needs tests, but for the record, files in the root of the public folder isn't really an edge case, there are lots of reasons they may be there. My particular case came from a d7-d8 migration, where the files were copied over in the root because that's where they were in D7
Comment #13
mondrakeHere's a test.
Comment #15
mikelutzComment #16
mondrakeFixed the PHPCS nit and updated issue title and summary.
Comment #17
borisson_Can be replaced by {@inheritdoc}
Why does this need the simpletest module?
Comment #18
mondrake#17.2 because there's a
drupal_get_path('module', 'simpletest')
a few lines below. TBH I do not know if that needs the module to be installed though. If it doesnt than yep that's supefluous.Comment #19
mohit1604 CreditAttribution: mohit1604 at Google Summer of Code commentedDid changes as per #17 and #18 , please review it :)
Comment #20
borisson_#17.2 wasn't fixed. But the test passes with the simpletest module removed from the modules to install.
Comment #21
runeasgar CreditAttribution: runeasgar as a volunteer commentedI am at the Drupalcon Nashville 2018 mentored sprint. I'm going to review this issue now.
Comment #22
runeasgar CreditAttribution: runeasgar as a volunteer commentedUnable to reproduce. I receive a 403, not a 404.
The instructions to reproduce are unclear (to me): "call the style url". I don't know what this means. My best interpretation was to hit the direct URL path where the "styled" image should reside. To test this, I created my image style (test_image_style) and changed the Article content type image field to use it for display. I then created an article, added an image, viewed the node, right clicked the image, and opened it in a new tab, which had this URL:
http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...
I placed a new file, test.png, directly in the /sites/default/files directory, then attempted to access it using these modified URLs:
http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...
http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...
http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...
All resulted in a 403, but I have confirmed that no image files exist at /sites/default/files/styles/test_image_style/public (so, why am I NOT getting a 404?).
Regardless, for kicks, I applied the patch. No change in the above-described behavior.
I assume I'm missing something. I'd be happy to re-test if someone can point out what I'm doing wrong.
Comment #23
mikelutzYour 403 comes from the fact that you haven't generated an image token to append to the end to authorize the image style generation. This one is tricky to reproduce because D8 doesn't want to put images in the root of the public files directory.
I haven't tested this, but off the top of my head, to reproduce without custom code, go with your first method, but edit your image field settings and remove [date:custom:Y]-[date:custom:m] from the File directory setting, so that the image is uploaded directly to the public files directory. Then you should get your proper tokenized url where the system cannot convert the file.
Comment #25
mikelutzConfirming that this bug still exists in 8.6 and 8.7, and the patch from #20 is still valid and solves the issue. I'm rerunning tests against 8.6 and 8.7, but I touched the patch above, so I can't RTBC.
Comment #26
eiriksmThis does not work if your default file scheme is private and you are trying to generate an image style for a public file.
file_build_uri ends up calling file_default_scheme. which is not what we want.
Working on this
Comment #27
eiriksmNot sure if we are allowed to change constructors, but would be nice to actually use a service instead of file_uri_scheme or static container calls.
Lets see if the tests pass at least.
Comment #28
eiriksmComment #29
eiriksmA bit quick, my patch was not in patch format :D
Comment #30
mikelutzWe can change the constructor AFAIK, since controllers use dependency injection. The signature of the create method is unchanged.
It probably needs an additional test testing against your case of a default private scheme and generating a style for a public file.
Comment #31
eiriksmYes i know but if my custom module extends this class my code would break. So it might be a bc breaking change.
Agree with the test. Just wanted to see if the tests passed first :)
Comment #32
mikelutzWhile that is true, controller constructors are not considered part of the API, and are subject to change, so you are all good.
@see https://www.drupal.org/core/d8-bc-policy#constructors
Comment #33
vacho CreditAttribution: vacho at Skilld commentedPatch rerolled
Comment #34
vacho CreditAttribution: vacho at Skilld commentedI Sorry patch #32 at comment #33 (first bad) is for 8.8.x version but I note that for this 8.8.x version the issue does not happen
Comment #35
jjcarrionI have tested 8.8.1 without the patch and this is still an issue. The reroll from comment #33 has a missing comma and a syntax error, so I have fixed that missing comma and the patch fixes the issue.
Here is the patch for version 8.8.x and the interdiff against the one from comment #33
Comment #37
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and commentedReroll to fix the unit tests and remove some deprecations.
Comment #38
TwiiK CreditAttribution: TwiiK at Ny Media AS commentedWe're using this patch with Drupal 8.8.2 in production with success so far. Without this patch png images in the root files folder could not be generated as image styles, with it they work as expected.
Edit: Patch from #37 that is.
Comment #40
hehongbo CreditAttribution: hehongbo commentedAlso encountered this issue in 8.8.5 after the adoption of responsive image and a series of image styles. Patch #37 works.
Comment #42
mightyulysses CreditAttribution: mightyulysses commentedAlso encountered this issue in 8.9.3. Patch #37 works beautifully.
Comment #43
mondrakeComment #44
mondrakeI think we need to make the assignment conditional with deprecation - if $file_system is null, it should be got form \Drupal::service
protected
assertEquals
$this->assertSession()->statusCodeEquals(200);
Comment #45
ayushmishra206 CreditAttribution: ayushmishra206 at OpenSense Labs commentedMade the changes requested in #44. Please review.
Comment #46
mondrakeThanks @ayushmishra206!
we cannot have a mandatory argument ($file_system) after an optional one ($stream_wrapper_manager), so $file_system = NULL is correct.
Re #44.1, we should have something like this:
with a @trigger_error if $file_system is null.
Comment #47
msutharsComment #48
msuthars@ayushmishra206 thanks for the work. I updated the patch as suggested by @mondrake. Please review.
Comment #49
mondrakedeprecated in drupal:9.1.0
Comment #50
vakulrai CreditAttribution: vakulrai as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedComment #51
vakulrai CreditAttribution: vakulrai as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedUpdated the @trigger_error message by replacing drupal:8.8.3 to drupal:9.1.0.
Comment #52
mondrakeThank you, RTBC - I shouldn't really but #38, #40 and #42 are supporting evidence.
Comment #53
larowlanNit: what is the use of final here for - we don't normally reference the argument position right?
Also - shouldn't we be adding a new deprecation test for this - per item 3 of https://www.drupal.org/core/deprecation#how
Comment #54
mondrakePer #3170185-14: Drupal\taxonomy\Form\OverviewTerms should determine the current page via the 'pager.manager' service, not from the Request, the deprecation test seems not necessary in this case.
NW to remove the word "final" from
Comment #55
ayushmishra206 CreditAttribution: ayushmishra206 at OpenSense Labs commentedWorking on #54
Comment #56
ayushmishra206 CreditAttribution: ayushmishra206 at OpenSense Labs commentedMade the change requested in #54. Please review.
Comment #57
mondrakeThanks!!
Comment #59
mondrakeRandom fail in #58
Comment #60
mondrakeComment #61
alexpottWe need a follow-up to fix
StreamWrapperManagerInterface $stream_wrapper_manager = NULL
- that cannot be NULL - we missed this in #3097453: Remove system.module BC layersCommitted aa12b0e and pushed to 9.1.x. Thanks!
Comment #63
mondrakeFiled #3174913: Fix StreamWrapperManagerInterface $stream_wrapper_manager argument in the constructor of ImageStyleDownloadController.
Comment #65
maximpodorov CreditAttribution: maximpodorov commentedWhat about fixing 8.x versions which have this annoying problem too?
Comment #66
eiriksmPatch applies to 8.9.x as well, but here it is. It's not possible for me to re-open this, but let's discuss if we should fix it first?
Also, the patch includes a text about deprecating in 9.1.x. Should we leave that?