Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
image.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
30 Sep 2022 at 20:59 UTC
Updated:
30 Nov 2022 at 21:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jan kellermann commentedComment #3
jan kellermann commentedComment #4
poker10 commentedComment #5
renefreund commentedPatch from #3 works like intended.
a newly created image-style-deriviate-file with bigger file-size than the source-image is now delivered by file_transfer() with the correct content-length header.
Comment #6
poker10 commentedThanks for filling this. It would be great if we can add a test for this. I think it could be possible to add something like in
ImageDimensionsTestCase::testImageDimensions(), but for the private filesystem and check the returned headers like it is done inImageStylesPathAndUrlTestCase::_testImageStyleUrlAndPath().Comment #7
jan kellermann commentedI attached a patch with some tests.
You need a private filesystem, image style with up- or downscale and the image-file saved in a node (only then file_file_download() populates the $headers).
(I do not really understand why we need a test to fix the bug in the last update. We only want to restore the 13 years old original code from @dries.)
ky.
Comment #8
jan kellermann commentedSmall bugfixes.
Comment #9
jan kellermann commentedFixed PHP5 testing-issue.
Comment #10
poker10 commentedThere are multiple reasons for this. The first thing is, if we encounter a bug, it is good to ensure that it won't happen again. So creating a test for the usecase will eliminate the possibility to accidentally come up in the future.
Second one is that a test provides all nessesary information and is a proof, that the problem exists. It can save some time for the core maintainers, because it clearly demonstrates that there is a problem. Other from that, issues with tests are more likely to be commited and fixed, as they are "complete".
The last one are some Drupal policies (which we should stick to). See: Upload-a-test-case-that-fails
Again, thanks for working on this. I have reviewed the patch and it looks good. The test is failing without the fix. I found some minor issues (mainly in comments), but overally it looks good to me:
The
$image_infodoes not seems to be used anywhere, so maybe these lines are redundant here.scale, should be Scale. Also consider renaming the test class to something like this: "ImageStylesHTTPHeadersTestCase" (see below).
Maybe something like this would be a better description: "Tests that images have correct file size, dimensions and HTTP headers when used in image styles with scaling."
There is a typo - dimmnsions should be dimensions. Other from that, I think that also this could be rephrased to something like this: "Image styles HTTP headers tests" and "Tests file size, dimensions and HTTP headers of image styles generated with scaling.".
Comment #11
jan kellermann commentedThank you very much for your feedback. Attached the new patch.
Comment #12
jan kellermann commentedAttached the patch with test only - which should fail without the patch drupal-3312970-1.patch
Comment #13
jan kellermann commentedRemark: The test for private and downscaling is not failing because apache is fixing Content-Length if response is shorter than 8000 bytes.
Comment #14
jan kellermann commentedI generate new tests with larger image because Apache generates own content-length if response is smaller than 8000 Bytes. Now the test for private with upscaling and downscaling should fail.
Comment #15
jan kellermann commentedAnd the diff with test only (2 tests should fail: private with upscaling and private with downscaling).
Comment #16
jan kellermann commentedComment #17
klonosThank you for working on this @ jan-kellermann 🙏
This function here is identical to
testImageStyleUrlAndPathPrivateAndUpscale(), so how about we create a single one (something liketestImageStyleUrlAndPathUpscale()) and we could then use an array of schemes that we iterate over?We could actually merge the other two functions that follow, and use another array that holds the upscale/downscale width and height pairs.
That would simplify the whole thing from 4 separate tests that are only 4-lines long and 99% identical, to a single
testImageStyleUrlAndPath()function/test that simply iterates over up-/down-scale and public/private schemes.Code looks good otherwise.
My 2c.
Comment #18
klonosComment #19
renefreund commentedJust because i am curious u/klonos. Is there anything to do here?
I found the bug and the solution. u/jan-kellermann provided the code + tests. But i want this fixed.
If there is anything to do, just tell us =)
Comment #20
mcdruid commentedI can see the point in #17 about how the tests could be refactored to loop over an array of test configs, but in this case I think the existing patch is fine; tests are often a bit repetitive.
Comment #22
mcdruid commentedUploading #14 again (no changes) to stop the testbot complaining that the most recent patch fails.
Comment #24
poker10 commentedThanks everyone and especially @jan kellermann for the great work here!