Pull up changes for 2.8.

Fix for ArcIMS GetFeatureInfo broken (Closes #2110)
  createUrlObject not working in IE (Closes #2060)



git-svn-id: http://svn.openlayers.org/branches/openlayers/2.8@9414 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2009-05-27 23:46:23 +00:00
parent aeff2e62df
commit 0b0d04b637
3 changed files with 132 additions and 105 deletions

View File

@@ -412,7 +412,7 @@ OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
if (!arcxml.iserror()) {
// if the arcxml is not an error, call the callback with the features parsed
callback.call(scope, arcxml.features);
callback.call(scope, response.features);
} else {
// if the arcxml is an error, return null features selected
callback.call(scope, null);

View File

@@ -1282,36 +1282,13 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
var urlObj1 = OpenLayers.Util.createUrlObject(url1, options);
var urlObj2 = OpenLayers.Util.createUrlObject(url2, options);
//compare all keys (host, port, etc)
//compare all keys except for "args" (treated below)
for(var key in urlObj1) {
if (options.test) {
OpenLayers.Console.userError(key + "\n1:" + urlObj1[key] + "\n2:" + urlObj2[key]);
if(key !== "args") {
if(urlObj1[key] != urlObj2[key]) {
return false;
}
}
var val1 = urlObj1[key];
var val2 = urlObj2[key];
switch(key) {
case "args":
//do nothing, they'll be treated below
break;
case "host":
case "port":
case "protocol":
if ((val1 == "") || (val2 == "")) {
//these will be blank for relative urls, so no need to
// compare them here -- call break.
//
break;
}
// otherwise continue with default compare
//
default:
if ( (key != "args") && (urlObj1[key] != urlObj2[key]) ) {
return false;
}
break;
}
}
// compare search args - irrespective of order
@@ -1350,7 +1327,7 @@ OpenLayers.Util.createUrlObject = function(url, options) {
if(!(/^\w+:\/\//).test(url)) {
var loc = window.location;
var port = loc.port ? ":" + loc.port : "";
var fullUrl = loc.protocol + "//" + loc.host + port;
var fullUrl = loc.protocol + "//" + loc.host.split(":").shift() + port;
if(url.indexOf("/") === 0) {
// full pathname
url = fullUrl + url;
@@ -1371,27 +1348,23 @@ OpenLayers.Util.createUrlObject = function(url, options) {
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) {
var newHostLength = urlObject.host.length - (port.length);
urlObject.host = urlObject.host.substring(0, newHostLength);
}
//host (without port)
urlObject.host = a.host.split(":").shift();
//protocol
//protocol
urlObject.protocol = a.protocol;
//port
urlObject.port = ((port == "80") && (options.ignorePort80)) ? "" : port;
//hash
urlObject.hash = (options.ignoreHash) ? "" : a.hash;
//port (get uniform browser behavior with port 80 here)
if(options.ignorePort80) {
urlObject.port = (a.port == "80" || a.port == "0") ? "" : a.port;
} else {
urlObject.port = (a.port == "" || a.port == "0") ? "80" : a.port;
}
//hash
urlObject.hash = (options.ignoreHash || a.hash === "#") ? "" : a.hash;
//args
//args
var queryString = a.search;
if (!queryString) {
var qMark = url.indexOf("?");
@@ -1399,65 +1372,9 @@ 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 != "")) ) {
urlObject.pathname = a.pathname;
//Test to see if the pathname includes the arguments (Opera)
var qIndex = urlObject.pathname.indexOf("?");
if (qIndex != -1) {
urlObject.pathname = urlObject.pathname.substring(0, qIndex);
}
} else {
var relStr = OpenLayers.Util.removeTail(url);
var backs = 0;
do {
var index = relStr.indexOf("../");
if (index == 0) {
backs++;
relStr = relStr.substr(3);
} else if (index >= 0) {
var prevChunk = relStr.substr(0,index - 1);
var slash = prevChunk.indexOf("/");
prevChunk = (slash != -1) ? prevChunk.substr(0, slash +1)
: "";
var postChunk = relStr.substr(index + 3);
relStr = prevChunk + postChunk;
}
} while(index != -1);
var windowAnchor = document.createElement("a");
var windowUrl = window.location.href;
if (options.ignoreCase) {
windowUrl = windowUrl.toLowerCase();
}
windowAnchor.href = windowUrl;
//set protocol of window
urlObject.protocol = windowAnchor.protocol;
var splitter = (windowAnchor.pathname.indexOf("/") != -1) ? "/" : "\\";
var dirs = windowAnchor.pathname.split(splitter);
dirs.pop(); //remove filename
while ((backs > 0) && (dirs.length > 0)) {
dirs.pop();
backs--;
}
relStr = dirs.join("/") + "/"+ relStr;
urlObject.pathname = relStr;
}
//pathname (uniform browser behavior with leading "/")
urlObject.pathname = (a.pathname.charAt(0) == "/") ? a.pathname : "/" + a.pathname;
if ((urlObject.protocol == "file:") || (urlObject.protocol == "")) {
urlObject.host = "localhost";
}
return urlObject;
};

View File

@@ -680,6 +680,116 @@
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "absolute and relative path without host works for "+url2)
}
function test_createUrlObject(t) {
var cases = [{
url: "http://example.com/",
exp: {
protocol: "http:",
host: "example.com",
port: "80",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com:80/",
opt: {ignorePort80: true},
exp: {
protocol: "http:",
host: "example.com",
port: "",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com/",
opt: {ignorePort80: true},
exp: {
protocol: "http:",
host: "example.com",
port: "",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com:88/",
exp: {
protocol: "http:",
host: "example.com",
port: "88",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com:88/foo#bar",
exp: {
protocol: "http:",
host: "example.com",
port: "88",
pathname: "/foo",
args: {},
hash: "#bar"
}
}, {
url: "http://example.com:88/?foo=bar",
exp: {
protocol: "http:",
host: "example.com",
port: "88",
pathname: "/",
args: {foo: "bar"},
hash: ""
}
}, {
url: "http://example.com/bogus/../bogus/../path",
exp: {
protocol: "http:",
host: "example.com",
port: "80",
pathname: "/path",
args: {},
hash: ""
}
}, {
url: "/relative#foo",
exp: {
protocol: window.location.protocol,
host: window.location.hostname,
port: window.location.port || "80",
pathname: "/relative",
args: {},
hash: "#foo"
}
}, {
url: "../foo",
exp: {
protocol: window.location.protocol,
host: window.location.hostname,
port: window.location.port || "80",
pathname: (function() {
var parts = window.location.pathname.split("/");
return parts.slice(0, parts.length -2).join("/") + "/foo";
})(),
args: {},
hash: ""
}
}];
t.plan(cases.length);
var c, obj;
for(var i=0; i<cases.length; ++i) {
c = cases[i];
obj = OpenLayers.Util.createUrlObject(c.url, c.opt);
t.eq(obj, c.exp, i + ": '" + c.url + "'");
}
}
function test_Util_createUniqueIDSeq(t) {
t.plan(1);