Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($resource): functions in params should not be executed if overridden #6480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,11 @@ angular.module('ngResource', ['ng']).
}
});

if (hasBody) httpConfig.data = data;
route.setUrlParams(httpConfig,
extend({}, extractParams(data, action.params || {}), params),
action.url);
if (hasBody) httpConfig.data = data;
params = extend({}, action.params || {}, params);
route.setUrlParams(httpConfig,
extractParams(data, params),
action.url);

var promise = $http(httpConfig).then(function (response) {
var data = response.data,
Expand Down
11 changes: 11 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,17 @@ describe("resource", function() {
inst.$post();
});

it('should not call function in action param if overriden', function() {
$httpBackend.expect('GET', '/item/123').respond({foo: 'bar'});

var TypeItem = $resource('/item/:id', {}, {get: {method: 'GET', params: {id: callback}}});
var item = TypeItem.get({id: 123}); // overrides params.id

$httpBackend.flush();

expect(callback).not.toHaveBeenCalled();
expect(item).toEqualData({foo: 'bar'});
});

it('should not throw TypeError on null default params', function() {
$httpBackend.expect('GET', '/Path').respond('{}');
Expand Down