[OpenLayers-Commits] r12250 - in trunk/openlayers:
lib/OpenLayers/Protocol tests/Protocol
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Aug 15 14:27:56 EDT 2011
Author: tschaub
Date: 2011-08-15 11:27:55 -0700 (Mon, 15 Aug 2011)
New Revision: 12250
Modified:
trunk/openlayers/lib/OpenLayers/Protocol/Script.js
trunk/openlayers/tests/Protocol/Script.html
Log:
Changing the named callback to avoid having the returned script call a function. This allows the protocol to be used with servers that sanitize callback identifiers for security. Great patch from vmische. r=me (closes 3417).
Modified: trunk/openlayers/lib/OpenLayers/Protocol/Script.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/Script.js 2011-08-15 16:30:43 UTC (rev 12249)
+++ trunk/openlayers/lib/OpenLayers/Protocol/Script.js 2011-08-15 18:27:55 UTC (rev 12250)
@@ -207,7 +207,7 @@
*/
createRequest: function(url, params, callback) {
var id = OpenLayers.Protocol.Script.register(callback);
- var name = "OpenLayers.Protocol.Script.getCallback(" + id + ")";
+ var name = "OpenLayers.Protocol.Script.registry[" + id + "]";
params = OpenLayers.Util.extend({}, params);
params[this.callbackKey] = this.callbackPrefix + name;
url = OpenLayers.Util.urlAppend(
@@ -328,7 +328,7 @@
(function() {
var o = OpenLayers.Protocol.Script;
var counter = 0;
- var registry = {};
+ o.registry = [];
/**
* Function: OpenLayers.Protocol.Script.register
@@ -344,7 +344,10 @@
*/
o.register = function(callback) {
var id = ++counter;
- registry[id] = callback;
+ o.registry[id] = function() {
+ o.unregister(id);
+ callback.apply(this, arguments);
+ };
return id;
};
@@ -356,22 +359,6 @@
* id: {Number} The identifer returned by the register function.
*/
o.unregister = function(id) {
- delete registry[id];
+ delete o.registry[id];
};
-
- /**
- * Function: OpenLayers.Protocol.Script.getCallback
- * Retreive and unregister a callback. A call to this function is the "P"
- * in JSONP. For example, a script may be added with a src attribute
- * http://example.com/features.json?callback=OpenLayers.Protocol.Script.getCallback(1)
- *
- * Parameters:
- * id: {Number} The identifer returned by the register function.
- */
- o.getCallback = function(id) {
- var callback = registry[id];
- o.unregister(id);
- return callback;
- };
})();
-
Modified: trunk/openlayers/tests/Protocol/Script.html
===================================================================
--- trunk/openlayers/tests/Protocol/Script.html 2011-08-15 16:30:43 UTC (rev 12249)
+++ trunk/openlayers/tests/Protocol/Script.html 2011-08-15 18:27:55 UTC (rev 12250)
@@ -150,7 +150,7 @@
t.eq(script.type, 'text/javascript',
'created script has a correct type');
- t.eq(script.src, 'http://bar_url/?k=bar_param&cb_key=cb_prefix%3AOpenLayers.Protocol.Script.getCallback(bar)',
+ t.eq(script.src, 'http://bar_url/?k=bar_param&cb_key=cb_prefix%3AOpenLayers.Protocol.Script.registry%5Bbar%5D',
'created script has a correct url');
t.eq(script.id, 'OpenLayers_Protocol_Script_bar',
'created script has a correct id');
More information about the Commits
mailing list