diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 7be1abd..365d5fa 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -798,10 +798,14 @@ function image_style_flush($style) { */ function image_style_url($style_name, $path) { $uri = image_style_path($style_name, $path); + + // The passed-in $path variable can be either a relative path or a full URI. + $original_uri = file_uri_scheme($path) ? file_stream_wrapper_uri_normalize($path) : file_build_uri($path); + // The token query is added even if the // 'image.settings:allow_insecure_derivatives' configuration is TRUE, so that // the emitted links remain valid if it is changed back to the default FALSE. - $token_query = array(IMAGE_DERIVATIVE_TOKEN => image_style_path_token($style_name, file_stream_wrapper_uri_normalize($path))); + $token_query = array(IMAGE_DERIVATIVE_TOKEN => image_style_path_token($style_name, $original_uri)); // If not using clean URLs, the image derivative callback is only available // with the script path. If the file does not exist, use url() to ensure diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php index 07ea3fb..9361251 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php @@ -140,6 +140,16 @@ function _testImageStyleUrlAndPath($scheme, $clean_url = TRUE, $extra_slash = FA $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', 'wrongparam=', $generate_url)); $this->assertResponse(403, 'Image was inaccessible at the URL wih a missing token.'); + // Check that the generated URL is the same when we pass in a relative path + // rather than a URI. We need to temporarily switch the default scheme to + // match the desired scheme before testing this, then switch it back to the + // "temporary" scheme used throughout this test afterwards. + config('system.file')->set('default_scheme', $scheme)->save(); + $relative_path = file_uri_target($original_uri); + $generate_url_from_relative_path = image_style_url($this->style_name, $relative_path); + $this->assertEqual($generate_url, $generate_url_from_relative_path, 'Generated URL is the same regardless of whether it came from a relative path or a file URI.'); + config('system.file')->set('default_scheme', 'temporary')->save(); + // Fetch the URL that generates the file. $this->drupalGet($generate_url); $this->assertResponse(200, 'Image was generated at the URL.');