From a4954415212b9c4a74db46bf6f55df5f0f3077c2 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 11 May 2010 10:56:04 +0000 Subject: - Patch #777830 by Wim Leers: file_create_url() does not support protocol-relative nor root-relative file URLs. --- includes/file.inc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'includes') diff --git a/includes/file.inc b/includes/file.inc index da47b3590..cb01ae24f 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -343,9 +343,21 @@ function file_create_url($uri) { $scheme = file_uri_scheme($uri); if (!$scheme) { - // If this is not a properly formatted stream, then it is a shipped file. - // Therefor, return the URI with the base URL prepended. - return $GLOBALS['base_url'] . '/' . $uri; + // 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 (drupal_substr($uri, 0, 1) == '/') { + return $uri; + } + else { + // If this is not a properly formatted stream, then it is a shipped file. + // Therefor, return the URI with the base URL prepended. + return $GLOBALS['base_url'] . '/' . $uri; + } } elseif ($scheme == 'http' || $scheme == 'https') { // Check for http so that we don't have to implement getExternalUrl() for -- cgit v1.2.3