make _getScriptLocation RegExp more robust, p=jpfiset, t,r=me

This commit is contained in:
Éric Lemoine
2012-04-04 20:30:50 +02:00
parent 5c597de900
commit b1b4736315
4 changed files with 7 additions and 7 deletions

View File

@@ -25,7 +25,7 @@ var OpenLayers = {
* {String} Path to this script * {String} Path to this script
*/ */
_getScriptLocation: (function() { _getScriptLocation: (function() {
var r = new RegExp("(^|(.*?\\/))(OpenLayers.*?\\.js)(\\?|$)"), var r = new RegExp("(^|(.*?\\/))(OpenLayers[^\\/]*?\\.js)(\\?|$)"),
s = document.getElementsByTagName('script'), s = document.getElementsByTagName('script'),
src, m, l = ""; src, m, l = "";
for(var i=0, len=s.length; i<len; i++) { for(var i=0, len=s.length; i<len; i++) {

View File

@@ -1,11 +1,11 @@
<html> <html>
<head> <head>
<script src="some/path/OpenLayers.js"></script> <script src="some/OpenLayers/path/OpenLayers.js"></script>
<script src="../lib/OpenLayers/SingleFile.js"></script> <script src="../lib/OpenLayers/SingleFile.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function test_OpenLayers(t) { function test_OpenLayers(t) {
t.plan(1); t.plan(1);
t.eq(OpenLayers._getScriptLocation(), "some/path/", t.eq(OpenLayers._getScriptLocation(), "some/OpenLayers/path/",
"Script location correctly detected (OpenLayers.js)."); "Script location correctly detected (OpenLayers.js).");
} }
</script> </script>

View File

@@ -1,11 +1,11 @@
<html> <html>
<head> <head>
<script src="some/path/OpenLayers.light.js"></script> <script src="some/OpenLayers/path/OpenLayers.light.js"></script>
<script src="../lib/OpenLayers/SingleFile.js"></script> <script src="../lib/OpenLayers/SingleFile.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function test_OpenLayers(t) { function test_OpenLayers(t) {
t.plan(1); t.plan(1);
t.eq(OpenLayers._getScriptLocation(), "some/path/", t.eq(OpenLayers._getScriptLocation(), "some/OpenLayers/path/",
"Script location correctly detected (OpenLayers.light.js)<29>."); "Script location correctly detected (OpenLayers.light.js)<29>.");
} }
</script> </script>

View File

@@ -1,11 +1,11 @@
<html> <html>
<head> <head>
<script src="some/path/OpenLayers.light.debug.js"></script> <script src="some/OpenLayers/path/OpenLayers.light.debug.js"></script>
<script src="../lib/OpenLayers/SingleFile.js"></script> <script src="../lib/OpenLayers/SingleFile.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function test_OpenLayers(t) { function test_OpenLayers(t) {
t.plan(1); t.plan(1);
t.eq(OpenLayers._getScriptLocation(), "some/path/", t.eq(OpenLayers._getScriptLocation(), "some/OpenLayers/path/",
"Script location correctly detected (OpenLayers.light.debug.js)."); "Script location correctly detected (OpenLayers.light.debug.js).");
} }
</script> </script>