diff --git a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php index c0ce73b..972d930 100644 --- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php @@ -155,13 +155,24 @@ protected function buildLocalUrl($uri, array $options = []) { * The options to merge in the defaults. */ protected function addOptionDefaults(array &$options) { + $request = $this->requestStack->getCurrentRequest(); + $current_base_path = $request->getBasePath() . '/'; + $current_script_path = ''; + $base_path_with_script = $request->getBaseUrl(); + if (!empty($base_path_with_script)) { + $script_name = $request->getScriptName(); + if (strpos($base_path_with_script, $script_name) !== FALSE) { + $current_script_path = ltrim(substr($script_name, strlen($current_base_path)), '/') . '/'; + } + } + // Merge in defaults. $options += [ 'fragment' => '', 'query' => [], 'absolute' => FALSE, 'prefix' => '', - 'script' => '', + 'script' => $current_script_path, ]; if (isset($options['fragment']) && $options['fragment'] !== '') { diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index a87554c..59eb2b6 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Routing\RequestHelper; use Drupal\Core\Site\Settings; +use Drupal\Core\Url; use Drupal\image\ImageEffectPluginCollection; use Drupal\image\ImageEffectInterface; use Drupal\image\ImageStyleInterface; @@ -222,7 +223,7 @@ public function buildUrl($path, $clean_urls = NULL) { // actual file path, this avoids bootstrapping PHP once the files are built. if ($clean_urls === FALSE && file_uri_scheme($uri) == 'public' && !file_exists($uri)) { $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath(); - return _url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query)); + return Url::fromUri('base://' . $directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query))->toString(); } $file_url = file_create_url($uri); diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php index 4c6272a..7bd4836 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -73,6 +73,7 @@ public function testAssembleWithNeitherExternalNorDomainLocalUri() { * @dataProvider providerTestAssembleWithExternalUrl */ public function testAssembleWithExternalUrl($uri, array $options, $expected) { + $this->setupRequestStack(FALSE); $this->assertEquals($expected, $this->unroutedUrlAssembler->assemble($uri, $options)); }