Forward port tests for image_style_deliver can create invalid headers

Created on 1 February 2016, over 8 years ago
Updated 14 March 2023, over 1 year ago

Problem/Motivation

Forward port tests for image_style_deliver can create invalid headers from #1891228: image_style_deliver can create invalid headers β†’

Change record for changes in D8 for the port
πŸ› Forward port tests for image_style_deliver can create invalid headers Needs work and the method is now ImageStyleDownloadController::deliver()

Original issue summary

image_style_deliver uses module_invoke_all to call hook_file_download, and module_invoke_all use array_merge_recursive to merge the results. This will be a problem if there is more than one hook_file_download returning the same header.
Example.
If two modules provide the header 'Content-Type' => 'image/jpeg', image_style_deliver will get an headers array looking like this.

array(
'Content-Type' => array(
'image/jpeg',
'image/jpeg',
),
)

And the result from that is that drupal_add_http_header will throw a notice (array to string).
I think image_style_deliver should behave like file_download does. So I created a patch to fix this... *phu* I hope anyone can read and understand this ;)

πŸ› Bug report
Status

Needs work

Version

9.4

Component
Image systemΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡¨πŸ‡¦Canada joelpittet Vancouver

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dww

    I didn't read the parent issue. I'm not sure I totally understand everything here, so take some of these review points with a dash of salt. πŸ˜‰ Mostly nits, but a few points of substance:

    1. +++ b/core/modules/image/tests/modules/image_module_test/image_module_test.module
      @@ -12,6 +12,10 @@ function image_module_test_file_download($uri) {
      +  if ($header_uri == $uri) {
      

      Should be ===

    2. +++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
      @@ -326,4 +326,23 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
      +   * Test that multiple same headers does not create a PHP notice.
      

      This doesn't follow our standards, and doesn't make a ton of English sense. How about:

      "Tests that a page with duplicate headers does not create a PHP notice."

      ? I'm not totally following what we're testing here. πŸ˜‰

    3. +++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
      @@ -326,4 +326,23 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
      +  public function testImageContentTypeHeaders() {
      

      a. wants a : void return type.

      b. Is that really what we're testing here? The name doesn't seem to match the comment above (if I understand the comment above πŸ˜…).

    4. +++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
      @@ -326,4 +326,23 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
      +    $files = $this->drupalGetTestFiles('image');
      +    $file = array_shift($files);
      ...
      +    $this->assertSession()->responseHeaderEquals('Content-Type', 'image/png');
      

      Does anything ensure that the first $file we get from drupalGetTestFiles() is definitely going to be a .png? If that ever changes, isn't this test going to silently stop proving anything?

    5. +++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
      @@ -326,4 +326,23 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
      +    $file_system = \Drupal::service('file_system');
      

      Since we only use this once, do we need the local variable for it?

    6. +++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
      @@ -326,4 +326,23 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
      +    // Copy the test file to private folder.
      

      ... to the private folder

    7. +++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
      @@ -326,4 +326,23 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
      +    // Clean up.
      +    \Drupal::state()->delete('image.test_invalid_headers');
      

      Do we also want/need to remove the file from the private folder here?

  • Assigned to RISHABH VISHWAKARMA
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Addressed points 1,2,3(a),5 and 6 from #23

  • Strangely running PHPCBF is making the patch fail. Adding the patch again.

  • Addressed points 1,2,3(a),5 and 6 from #23

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks for the interest

    Shouldn't be moved to review until all the points are addressed. But helps that some of them have been!

Production build 0.69.0 2024