diff --git a/core/modules/config/lib/Drupal/config/Controller/ConfigController.php b/core/modules/config/lib/Drupal/config/Controller/ConfigController.php index a84931c..3861ca8 100644 --- a/core/modules/config/lib/Drupal/config/Controller/ConfigController.php +++ b/core/modules/config/lib/Drupal/config/Controller/ConfigController.php @@ -82,7 +82,7 @@ public function downloadExport() { $file_controller = new FileDownloadController($this->moduleHandler); $request = new Request(array('file' => 'config.tar.gz')); - return $file_controller->fileDownload($request, 'temporary'); + return $file_controller->download($request, 'temporary'); } /** diff --git a/core/modules/image/image.module b/core/modules/image/image.module index f57b1a8..81dee76 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -14,6 +14,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Drupal\Component\Utility\Crypt; +use Drupal\Component\Utility\Url; use Drupal\Component\Uuid\Uuid; use Drupal\file\Plugin\Core\Entity\File; use Drupal\image\Plugin\Core\Entity\ImageStyle; @@ -537,7 +538,7 @@ function image_style_url($style_name, $path, $clean_urls = NULL) { // Append the query string with the token, if necessary. if ($token_query) { - $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . Drupal::urlGenerator()->httpBuildQuery($token_query); + $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . Url::buildQuery($token_query); } return $file_url; diff --git a/core/modules/image/lib/Drupal/image/Controller/ImageStyleDownloadController.php b/core/modules/image/lib/Drupal/image/Controller/ImageStyleDownloadController.php index c95eeab..d63f61c 100644 --- a/core/modules/image/lib/Drupal/image/Controller/ImageStyleDownloadController.php +++ b/core/modules/image/lib/Drupal/image/Controller/ImageStyleDownloadController.php @@ -95,11 +95,11 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st $target = $request->query->get('file'); // Check that the style is defined, the scheme is valid, and the image - // derivative token is valid. (Sites which require image derivatives to be + // derivative token is valid. Sites which require image derivatives to be // generated without a token can set the // 'image.settings:allow_insecure_derivatives' configuration to TRUE to bypass // the latter check, but this will increase the site's vulnerability to - // denial-of-service attacks.) + // denial-of-service attacks. $valid = !empty($image_style) && file_stream_wrapper_valid_scheme($scheme); if (!$this->configFactory->get('image.settings')->get('allow_insecure_derivatives')) { $valid = $valid && $request->query->get(IMAGE_DERIVATIVE_TOKEN) === image_style_path_token($image_style->name, $scheme . '://' . $target); @@ -117,7 +117,7 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st // control access to the file. if ($scheme == 'private') { if (file_exists($derivative_uri)) { - return parent::deliver($request, $scheme); + return parent::download($request, $scheme); } else { $headers = $this->moduleHandler->invokeAll('file_download', array($image_uri)); diff --git a/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php b/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php index 37f7047..6cdbc7c 100644 --- a/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php +++ b/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php @@ -43,7 +43,7 @@ public function dynamicRoutes(RouteBuildEvent $event) { $route = new Route('/' . $directory_path . '/styles/{image_style}/{scheme}', array( - '_controller' => 'Drupal\image\Controller\ImageStyleFileService::deliver', + '_controller' => 'Drupal\image\Controller\ImageStyleDownloadController::deliver', ), array( '_access' => 'TRUE', diff --git a/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php b/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php index ea26f2f..c0c6f31 100644 --- a/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php +++ b/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php @@ -17,14 +17,13 @@ * the file path to a query parameter on the request. * * This processor handles two different cases: - * - public image styles: In order to allow apache to serve this files - * directly, the route is registered under the same path as the image style - * so it took over the first generation. Therefore the path processor - * converts the file path to a query parameter and a request on - * directory/styles/$image_style/public. - * - private image styles: In contrast to public image styles, private one - * already use system/files/styles. Similar to public image styles, it - * also converts the file path to a query parameter. + * - public image styles: In order to allow the webserver to serve these files + * directly, the route is registered under the same path as the image style so + * it took over the first generation. Therefore the path processor converts + * the file path to a query parameter. + * - private image styles: In contrast to public image styles, private + * derivatives are already using system/files/styles. Similar to public image + * styles, it also converts the file path to a query parameter. */ class PathProcessorImageStyles implements InboundPathProcessorInterface { @@ -34,44 +33,25 @@ class PathProcessorImageStyles implements InboundPathProcessorInterface { public function processInbound($path, Request $request) { $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(); if (strpos($path, $directory_path . '/styles/') === 0) { - $rest = str_replace($directory_path .'/styles/', '', $path); - - // Get the image style, schema and actual url. - list($image_style, $scheme, $rest) = explode('/', $rest, 3); - - // Set file as query parameter on the route. There might be additional - // keys like itok, set them as query parameter as well. - $query = drupal_get_query_array($rest); - foreach ($query as $key => $value) { - if (!isset($value) && !$request->query->has('file')) { - $request->query->set('file', $key); - } - else { - $request->query->set($key, $value); - } - } - $path = $directory_path . '/styles/' . $image_style .'/' . $scheme; + $path_prefix = $directory_path . '/styles/'; } elseif (strpos($path, 'system/files/styles/') === 0) { - $rest = str_replace('system/files/styles/', '', $path); + $path_prefix = 'system/files/styles/'; + } + else { + return $path; + } - // Get the image style, schema and actual url. - list($image_style, $scheme, $file_path) = explode('/', $rest); + // Strip out path prefix. + $rest = preg_replace('|^' . $path_prefix . '|', '', $path); - // Set file as query parameter on the route. There might be additional - // keys like itok, set them as query parameter as well. - $query = drupal_get_query_array($file_path); - foreach ($query as $key => $value) { - if (!isset($value) && !$request->query->has('file')) { - $request->query->set('file', $key); - } - else { - $request->query->set($key, $value); - } - } - $path = 'system/files/styles/' . $image_style . '/' . $scheme; - } - return $path; + // Get the image style, scheme and path. + list($image_style, $scheme, $file) = explode('/', $rest, 3); + + // Set the file as query parameter. + $request->query->set('file', $file); + + return $path_prefix . $image_style . '/' . $scheme; } } diff --git a/core/modules/system/lib/Drupal/system/FileDownloadController.php b/core/modules/system/lib/Drupal/system/FileDownloadController.php index 15bc4eb..c4f7719 100644 --- a/core/modules/system/lib/Drupal/system/FileDownloadController.php +++ b/core/modules/system/lib/Drupal/system/FileDownloadController.php @@ -71,7 +71,7 @@ public static function create(ContainerInterface $container) { * @return \Symfony\Component\HttpFoundation\BinaryFileResponse * The transferred file as response. */ - public function deliver(Request $request, $scheme = 'private') { + public function download(Request $request, $scheme = 'private') { $target = $request->query->get('file'); // Merge remaining path arguments into relative file path. $uri = $scheme . '://' . $target; diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index a1c7ae1..dbbc5d6 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -147,7 +147,7 @@ system_admin_index: system_files: pattern: '/system/files/{scheme}' defaults: - _controller: 'Drupal\system\FileDownloadController::deliver' + _controller: 'Drupal\system\FileDownloadController::download' scheme: private requirements: _access: 'TRUE'