diff --git a/lib/OpenLayers/Protocol/HTTP.js b/lib/OpenLayers/Protocol/HTTP.js index 3b5d3f9572..2b86c0c77e 100644 --- a/lib/OpenLayers/Protocol/HTTP.js +++ b/lib/OpenLayers/Protocol/HTTP.js @@ -175,9 +175,10 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { */ read: function(options) { OpenLayers.Protocol.prototype.read.apply(this, arguments); - options = OpenLayers.Util.applyDefaults(options, this.options); + options = options || {}; options.params = OpenLayers.Util.applyDefaults( options.params, this.options.params); + options = OpenLayers.Util.applyDefaults(options, this.options); if (options.filter && this.filterToParams) { options.params = this.filterToParams( options.filter, options.params diff --git a/tests/Protocol/HTTP.html b/tests/Protocol/HTTP.html index 6d2e26b186..fac460b547 100644 --- a/tests/Protocol/HTTP.html +++ b/tests/Protocol/HTTP.html @@ -779,7 +779,7 @@ }); protocol.read(); - t.delay_call(1, function() { + t.delay_call(2, function() { t.eq(log1.callbackCalled, true, "[read] callback called"); t.eq(log1.callbackScope, scope, "[read] correct scope"); t.ok(log1.request instanceof OpenLayers.Request.XMLHttpRequest, "[read] correct priv type"); @@ -801,11 +801,37 @@ {state: OpenLayers.State.DELETE, url: "./3"}, {state: OpenLayers.State.DELETE, url: "./4"} ]); - t.delay_call(1, function() { + t.delay_call(2, function() { t.eq(log2.called, 1, "[commit] Callback called once."); t.eq(log2.scope, scope, "[commit] Correct scope."); }); + } + function test_read_global_options(t) { + + // test that calling read doesn't write params into the protocol's + // options object, see ticket #3237 + + t.plan(2); + + var protocol = new OpenLayers.Protocol.HTTP({ + url: '.', + callback: function() {}, + params: {'a': 'a'} + }); + + // check initial state first + t.eq(protocol.options.params, {'a': 'a'}, + 'protocol params are ok at initial state'); + + var filter = new OpenLayers.Filter.Comparison({ + type: OpenLayers.Filter.Comparison.EQUAL_TO, + property: 'b', + value: 'b' + }); + protocol.read({filter: filter}); + t.eq(protocol.options.params, {'a': 'a'}, + "protocol params are ok after read"); }