diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php index 99a2b1e..4419419 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php @@ -78,9 +78,8 @@ function getUri() { * @param string $uri * Optional URI. * - * @return string|bool - * Returns a string representing a location suitable for writing of a file, - * or FALSE if unable to write to the file such as with read-only streams. + * @return string + * Returns a string representing a location suitable for writing of a file. * * @throws \InvalidArgumentException * If a malformed $uri parameter is passed in. @@ -308,7 +307,7 @@ public function stream_close() { * @param int $cast_as * Can be STREAM_CAST_FOR_SELECT or STREAM_CAST_AS_STREAM. * - * @return resource|FALSE + * @return resource|false * The underlying stream resource or FALSE if stream_select() is not * supported. * diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php index 3f9f5d4..8fe1d1f 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php @@ -86,7 +86,7 @@ public function realpath(); * An optional URI. * * @return string - * A string containing the directory name, or FALSE if not applicable. + * A string containing the directory name. * * @see drupal_dirname() */ diff --git a/core/lib/Drupal/Core/StreamWrapper/SystemStream.php b/core/lib/Drupal/Core/StreamWrapper/SystemStream.php index 5d53458..4460ee6 100644 --- a/core/lib/Drupal/Core/StreamWrapper/SystemStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/SystemStream.php @@ -48,9 +48,9 @@ public function getOwnerName($uri = NULL) { * {@inheritdoc} */ public function getTarget($uri = NULL) { - $target = $this->extractTarget($uri); - if (file_exists($this->getDirectoryPath($uri) . '/' . $target)) { - return $target; + $target = strstr(parent::getTarget($uri), '/') ?: ''; + if (file_exists($this->getDirectoryPath($uri) . $target)) { + return trim($target, '/'); } else { throw new \InvalidArgumentException(sprintf('Target %s does not exist', $uri)); @@ -58,27 +58,6 @@ public function getTarget($uri = NULL) { } /** - * Returns the local target of the resource, regardless of whether it exists. - * - * @param string $uri - * Optional URI. - * - * @return string - * A path to the local target. - * - * @throws \InvalidArgumentException - */ - protected function extractTarget($uri = NULL) { - // If the owner doesn't exist at all, we don't extract anything. - if ($this->getOwnerName($uri)) { - $target = parent::getTarget($uri); - // Remove the preceding owner name including slash from the path. - $start = strpos($target, '/'); - return ($start === FALSE) ? '' : substr($target, $start + 1); - } - } - - /** * Returns a web accessible URL for the resource. * * This function should return a URL that can be embedded in a web page @@ -86,6 +65,9 @@ protected function extractTarget($uri = NULL) { * "youtube://xIpLd0WQKCY" might be * "http://www.youtube.com/watch?v=xIpLd0WQKCY". * + * @param string $uri + * An optional URI. + * * @return string * Returns a string containing a web accessible URL for the resource. * @@ -97,8 +79,12 @@ public function getExternalUrl($uri = NULL) { throw new \InvalidArgumentException(sprintf('Extension directory for %s does not exist.', $uri)); } - $target = $this->extractTarget($uri); - $path = $target != '' ? '/' . UrlHelper::encodePath(str_replace('\\', '/', $target)) : ''; + // Find the path following the owner name. + if ($path = strstr(parent::getTarget($uri), '/')) { + // Clean the path. + $path = rtrim(UrlHelper::encodePath(str_replace('\\', '/', $path)), '/'); + } + return \Drupal::request()->getUri() . $dir . $path; } } diff --git a/core/modules/system/src/Tests/File/SystemStreamUnitTest.php b/core/modules/system/src/Tests/File/SystemStreamUnitTest.php index be33a14..456ec98 100644 --- a/core/modules/system/src/Tests/File/SystemStreamUnitTest.php +++ b/core/modules/system/src/Tests/File/SystemStreamUnitTest.php @@ -404,7 +404,7 @@ private function runTestOnInstanceMethod($instance, $method, array $data) { } } else { - $this->assertEqual($instance->$method($uri), $info[0], $info[1]); + $this->assertEqual($instance->$method($uri), $info[0]/*, $info[1]*/); } } }