Opened 3 years ago

Last modified 3 years ago

#3642 new bug

Layer switcher button broken (_getScriptLocation) in OpenLayers-2.12-rc1

Reported by: jpfiset Owned by:
Priority: minor Milestone: 2.13 Release
Component: general Version: 2.11
Keywords: Cc:
State:

Description

When using the single file version of OpenLayers, the layer selector button is broken (the path to the file layer-switcher-maximize.png is invalid). However, when using the developer's version of the library (lib/OpenLayers.js), the button is shown properly.

The issue comes from the fact that the routine to compute the script location in SingleFile.js was modified and the regex, in some circumstances, matches the wrong portion for the script path.

If a portion of the path to the single file library OpenLayers.js contains the pattern "OpenLayers", then the regex matches the wrong portion of the path. Here are some examples.

"js/OpenLayers.js" matches correctly.

"js/OpenLayers/OpenLayers.js" does not match correctly.

The fix is to change the regex in SingleFile.js from

var r = new RegExp("(|(.*?
/))(OpenLayers.*?
.js)(
?|$)")

to

var r = new RegExp("(|(.*?
/))(OpenLayers[

/]*?
.js)(
?|$)")

This modification prevents the matching of the path separator within the library name.

Here is the same modification, but in a patch form:

diff --git a/lib/OpenLayers/SingleFile.js b/lib/OpenLayers/SingleFile.js index 234c9c0..ae34ef9 100644 --- a/lib/OpenLayers/SingleFile.js +++ b/lib/OpenLayers/SingleFile.js @@ -25,7 +25,7 @@ var OpenLayers = {

  • {String} Path to this script */

_getScriptLocation: (function() {

  • var r = new RegExp("(|(.*?
    /))(OpenLayers.*?
    .js)(
    ?|$)"),

+ var r = new RegExp("(|(.*?
/))(OpenLayers[

/]*?
.js)(
?|$)"),

s = document.getElementsByTagName('script'), src, m, l = "";

for(var i=0, len=s.length; i<len; i++) {

Attachments (1)

ol_3642.patch (581 bytes) - added by jpfiset 3 years ago.
Patch shown in description

Download all attachments as: .zip

Change History (2)

Changed 3 years ago by jpfiset

Patch shown in description

Note: See TracTickets for help on using tickets.