From 51b1937aa6945902ae6a3fc12ada83bbb1ceae64 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 27 Apr 2009 20:57:14 +0000 Subject: [PATCH] fix for urls with same host in createUrlObject in IE. r=tschaub (pullup #2060) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9320 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 6 ++++-- tests/Util.html | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 4c0eab1bcf..d31c1dc6fb 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1356,7 +1356,10 @@ OpenLayers.Util.createUrlObject = function(url, options) { a.href = url; //host (without port) - urlObject.host = a.host; + // 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) { var newHostLength = urlObject.host.length - (port.length); @@ -1380,7 +1383,6 @@ OpenLayers.Util.createUrlObject = function(url, options) { } urlObject.args = OpenLayers.Util.getParameters(queryString); - //pathname (this part allows for relative <-> absolute comparison) if ( ((urlObject.protocol == "file:") && (url.indexOf("file:") != -1)) || ((urlObject.protocol != "file:") && (urlObject.host != "")) ) { diff --git a/tests/Util.html b/tests/Util.html index 4e92d8c2ab..9d0982933c 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -606,7 +606,7 @@ } function test_Util_isEquivalentUrl(t) { - t.plan(8); + t.plan(9); var url1, url2, options; @@ -663,7 +663,12 @@ url1 = "foo.html?bar=now#go"; url2 = "../tests/../tests/foo.html?bar=now#go"; - t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "relative vs. absolute paths works"); + t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "relative vs. absolute paths works"); + + url1 = "/foo/bar"; + url2 = new Array(window.location.pathname.split("/").length-1).join("../")+"foo/bar"; + + t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "absolute and relative path without host works for "+url2) } function test_Util_createUniqueIDSeq(t) {