diff -u b/core/includes/file.inc b/core/includes/file.inc --- b/core/includes/file.inc +++ b/core/includes/file.inc @@ -205,8 +205,7 @@ * A string containing a URL that may be used to access the file. * If the provided string already contains a preceding 'http', 'https', or * '/', nothing is done and the same string is returned. If a stream wrapper - * could not be found to generate an external URL or a file doesn't have an - * external URL, then FALSE is returned. + * could not be found to generate an external URL, then FALSE is returned. * * @see https://www.drupal.org/node/515192 * @see file_url_transform_relative() @@ -214,57 +213,58 @@ function file_create_url($uri) { // Allow the URI to be altered, e.g. to serve a file from a CDN or static // file server. - try { - \Drupal::moduleHandler()->alter('file_url', $uri); + \Drupal::moduleHandler()->alter('file_url', $uri); - $scheme = StreamWrapperManager::getScheme($uri); + $scheme = StreamWrapperManager::getScheme($uri); - if (!$scheme) { - // Allow for: - // - root-relative URIs (e.g. /foo.jpg in http://example.com/foo.jpg) - // - protocol-relative URIs (e.g. //bar.jpg, which is expanded to - // http://example.com/bar.jpg by the browser when viewing a page over - // HTTP and to https://example.com/bar.jpg when viewing a HTTPS page) - // Both types of relative URIs are characterized by a leading slash, hence - // we can use a single check. - if (mb_substr($uri, 0, 1) == '/') { - return $uri; + if (!$scheme) { + // Allow for: + // - root-relative URIs (e.g. /foo.jpg in http://example.com/foo.jpg) + // - protocol-relative URIs (e.g. //bar.jpg, which is expanded to + // http://example.com/bar.jpg by the browser when viewing a page over + // HTTP and to https://example.com/bar.jpg when viewing a HTTPS page) + // Both types of relative URIs are characterized by a leading slash, hence + // we can use a single check. + if (mb_substr($uri, 0, 1) == '/') { + return $uri; + } + else { + // If this is not a properly formatted stream, then it is a shipped file. + // Therefore, return the urlencoded URI with the base URL prepended. + $options = UrlHelper::parse($uri); + $path = $GLOBALS['base_url'] . '/' . UrlHelper::encodePath($options['path']); + // Append the query. + if ($options['query']) { + $path .= '?' . UrlHelper::buildQuery($options['query']); } - else { - // If this is not a properly formatted stream, then it is a shipped file. - // Therefore, return the urlencoded URI with the base URL prepended. - $options = UrlHelper::parse($uri); - $path = $GLOBALS['base_url'] . '/' . UrlHelper::encodePath($options['path']); - // Append the query. - if ($options['query']) { - $path .= '?' . UrlHelper::buildQuery($options['query']); - } - - // Append fragment. - if ($options['fragment']) { - $path .= '#' . $options['fragment']; - } - return $path; + // Append fragment. + if ($options['fragment']) { + $path .= '#' . $options['fragment']; } + + return $path; } - elseif ($scheme == 'http' || $scheme == 'https' || $scheme == 'data') { - // Check for HTTP and data URI-encoded URLs so that we don't have to - // implement getExternalUrl() for the HTTP and data schemes. - return $uri; - } - else { - // Attempt to return an external URL using the appropriate wrapper. - /* @var \Drupal\Core\StreamWrapper\StreamWrapperInterface $wrapper */ - if ($wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($uri)) { + } + elseif ($scheme == 'http' || $scheme == 'https' || $scheme == 'data') { + // Check for HTTP and data URI-encoded URLs so that we don't have to + // implement getExternalUrl() for the HTTP and data schemes. + return $uri; + } + else { + // Attempt to return an external URL using the appropriate wrapper. + if ($wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($uri)) { + try { return $wrapper->getExternalUrl(); } + catch (\Exception $e) { + } + return FALSE; + } + else { + return FALSE; } } - catch (\Exception $e) { - } - - return FALSE; } /** reverted: --- b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php +++ a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php @@ -145,9 +145,8 @@ * "youtube://xIpLd0WQKCY" might be * "http://www.youtube.com/watch?v=xIpLd0WQKCY". * + * @return string + * Returns a string containing a web accessible URL for the resource. - * @return string|false - * Returns a string containing a web accessible URL for the resource or - * FALSE if a stream doesn't/cannot provide the URL. */ public function getExternalUrl(); reverted: --- b/core/modules/locale/src/StreamWrapper/TranslationsStream.php +++ a/core/modules/locale/src/StreamWrapper/TranslationsStream.php @@ -41,11 +41,12 @@ } /** + * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::getExternalUrl(). + * @throws \LogicException + * PO files URL should not be public. - * {@inheritdoc} */ public function getExternalUrl() { + throw new \LogicException('PO files URL should not be public.'); - // PO files URL should not be public. - return FALSE; } }