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

fix($resource): append extra params even if Object.prototype has properties with the same name #14867

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ angular.module('ngResource', ['ng']).
encodedVal,
protocolAndDomain = '';

var urlParams = self.urlParams = {};
var urlParams = self.urlParams = Object.create(null);
forEach(url.split(/\W/), function(param) {
if (param === 'hasOwnProperty') {
throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name.");
Expand Down
43 changes: 43 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,49 @@ describe("basic usage", function() {
});
});

describe('extra params', function() {
var $http;
var $httpBackend;
var $resource;

beforeEach(module('ngResource'));

beforeEach(module(function($provide) {
$provide.decorator('$http', function($delegate) {
return jasmine.createSpy('$http').and.callFake($delegate);
});
}));

beforeEach(inject(function(_$http_, _$httpBackend_, _$resource_) {
$http = _$http_;
$httpBackend = _$httpBackend_;
$resource = _$resource_;
}));

afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
});


it('should pass extra params to `$http` as `config.params`', function() {
$httpBackend.expectGET('/bar?baz=qux').respond('{}');

var R = $resource('/:foo');
R.get({foo: 'bar', baz: 'qux'});

expect($http).toHaveBeenCalledWith(jasmine.objectContaining({params: {baz: 'qux'}}));
});

it('should pass extra params even if `Object.prototype` has properties with the same name',
function() {
$httpBackend.expectGET('/foo?toString=bar').respond('{}');

var R = $resource('/foo');
R.get({toString: 'bar'});
}
);
});

describe('errors', function() {
var $httpBackend, $resource, $q;

Expand Down