From 52a4d4f8cc7189ce8e984ff617a492292be48a93 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 21 May 2009 18:27:26 +0000 Subject: [PATCH] Making it so createUrlObject casts all urls to absolute ones first. r=crschmidt (pullup #2060) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9404 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 8d63340d1e..3a3ef27493 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1346,7 +1346,21 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) { OpenLayers.Util.createUrlObject = function(url, options) { options = options || {}; - var urlObject = {}; + // deal with relative urls first + if(!(/^\w+:\/\//).test(url)) { + var loc = window.location; + var port = loc.port ? ":" + loc.port : ""; + var fullUrl = loc.protocol + "//" + loc.host + port; + if(url.indexOf("/") === 0) { + // full pathname + url = fullUrl + url; + } else { + // relative to current path + var parts = loc.pathname.split("/"); + parts.pop(); + url = fullUrl + parts.join("/") + "/" + url; + } + } if (options.ignoreCase) { url = url.toLowerCase(); @@ -1355,13 +1369,15 @@ OpenLayers.Util.createUrlObject = function(url, options) { var a = document.createElement('a'); a.href = url; + var urlObject = {}; + //host (without port) // if we don't have a host (which is the case with URLs starting with "/" // in IE), take the window location's host to match other browsers that // fill in the window's location host automatically urlObject.host = a.host || window.location.host; var port = a.port; - if (port.length <= 0) { + if (port.length > 0) { var newHostLength = urlObject.host.length - (port.length); urlObject.host = urlObject.host.substring(0, newHostLength); }