diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index e755788845..29f964cf22 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -37,28 +37,22 @@ * {String} Path to this script */ _getScriptLocation: function () { - var scriptLocation = ""; - var scriptName = OpenLayers._scriptName; + var scriptLocation = ""; + var isOL = new RegExp("(^|(.*?\\/))(" + OpenLayers._scriptName + ")(\\?|$)"); var scripts = document.getElementsByTagName('script'); for (var i=0, len=scripts.length; i -1) && (index + scriptName.length == pathLength)) { - scriptLocation = src.slice(0, pathLength - scriptName.length); + var match = src.match(isOL); + if(match) { + scriptLocation = match[1]; break; } } } return scriptLocation; - } + } }; /** * OpenLayers.singleFile is a flag indicating this file is being included diff --git a/tests/OpenLayers.html b/tests/OpenLayers.html index 947d3c6598..89081d7983 100644 --- a/tests/OpenLayers.html +++ b/tests/OpenLayers.html @@ -1,19 +1,24 @@ - - + + + + t.eq(OpenLayers._getScriptLocation(), "../", "Script location correctly detected."); + script.setAttribute("src", "../lib/OpenLayers.js?foo"); + t.eq(OpenLayers._getScriptLocation(), "../", "Script location with search string correctly detected."); + + // now pretend we're using a built script + OpenLayers._scriptName = "OpenLayers.js"; + t.eq(OpenLayers._getScriptLocation(), "../lib/", "not fooled by bogus paths"); + + } +