summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-05-11 10:56:04 +0000
committerDries Buytaert <dries@buytaert.net>2010-05-11 10:56:04 +0000
commita4954415212b9c4a74db46bf6f55df5f0f3077c2 (patch)
tree1278968261898dace08e74e91edb7bfd90440137 /includes
parent8b0871244950bd389e82fc38809af09124ba60c3 (diff)
downloadbrdo-a4954415212b9c4a74db46bf6f55df5f0f3077c2.tar.gz
brdo-a4954415212b9c4a74db46bf6f55df5f0f3077c2.tar.bz2
- Patch #777830 by Wim Leers: file_create_url() does not support protocol-relative nor root-relative file URLs.
Diffstat (limited to 'includes')
-rw-r--r--includes/file.inc18
1 files changed, 15 insertions, 3 deletions
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