From 80258d7f914860c79db4ca09bef2042a24ae82a8 Mon Sep 17 00:00:00 2001
From: Pol Dell'Aiera
Date: Sun, 19 Aug 2012 19:44:10 +0200
Subject: [PATCH] Issue #1694048: JS file URL (openlayers_source) should respect RFC 1808 Section 4
---
.../openlayers_ui/includes/openlayers_ui.admin.inc | 6 ++++--
openlayers.module | 7 +++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/modules/openlayers_ui/includes/openlayers_ui.admin.inc b/modules/openlayers_ui/includes/openlayers_ui.admin.inc
index eca84f3..74a752d 100644
--- a/modules/openlayers_ui/includes/openlayers_ui.admin.inc
+++ b/modules/openlayers_ui/includes/openlayers_ui.admin.inc
@@ -19,7 +19,9 @@ function openlayers_ui_admin_settings() {
OpenLayers library at %ol_api_url.
For better performance and reliability, you should download the
OpenLayers library, and add it to your Drupal installation. For instance,
- you could use a Drupal relative path like: %suggested_path.
+ you could use a Drupal relative path like: %suggested_path. You can also use a double backslash
+ before the domain name (eg. //www.example.com/OpenLayers.js) which
+ then respects the use of both HTTPS and HTTP protocols.
- The default suggested, compatible version: %suggested_api
- The default suggested, compatible hosted URL: %ol_api_url
@@ -104,4 +106,4 @@ function openlayers_ui_version_check($version = 0) {
'status' => $status,
'response' => $message,
));
-}
\ No newline at end of file
+}
diff --git a/openlayers.module b/openlayers.module
index 95d5ddf..18a314f 100644
--- a/openlayers.module
+++ b/openlayers.module
@@ -109,6 +109,13 @@ function openlayers_include() {
$once = TRUE;
$path = check_plain(variable_get('openlayers_source', OPENLAYERS_DEFAULT_LIBRARY));
+
+ // Correctly handle URLs beginning with a double backslash, see RFC 1808 Section 4
+ if (substr($path, 0, 2) == '//') {
+ $http_protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
+ $path = $http_protocol .':'. $path;
+ }
+
// Check for full URL and include it manually if external.
if (valid_url($path, TRUE)) {
drupal_add_js($path, 'external');
--
1.7.3.4