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

fix(ngResource): restore shallowClearAndCopy properties fitlering condition #5666

Closed
wants to merge 4 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/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ function shallowCopy(src, dst) {
for(var key in src) {
// shallowCopy is only ever called by $compile nodeLinkFn, which has control over src
// so we don't need to worry about using our custom hasOwnProperty here
if (src.hasOwnProperty(key) && key.charAt(0) !== '$' && key.charAt(1) !== '$') {
if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
dst[key] = src[key];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function shallowClearAndCopy(src, dst) {
});

for (var key in src) {
if (src.hasOwnProperty(key) && key.charAt(0) !== '$' && key.charAt(1) !== '$') {
if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
dst[key] = src[key];
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ describe('angular', function() {
expect(clone.$$some).toBeUndefined();
expect(clone.$$).toBeUndefined();
});

it('should not remove $ properties from copy', function() {
var original = {$some: true};
var clone = {};

expect(shallowCopy(original, clone)).toBe(clone);
expect(clone.$some).toBe(original.$some);
});
});

describe('elementHTML', function() {
Expand Down
25 changes: 25 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ describe("resource", function() {
expect(typeof CreditCard.query).toBe('function');
});

describe('shallow copy', function() {
it('should make a copy', function() {
var original = {key:{}};
var copy = shallowClearAndCopy(original);
expect(copy).toEqual(original);
expect(copy.key).toBe(original.key);
});

it('should not copy $$ properties nor prototype properties', function() {
var original = {$$some: true, $$: true};
var clone = {};

expect(shallowClearAndCopy(original, clone)).toBe(clone);
expect(clone.$$some).toBeUndefined();
expect(clone.$$).toBeUndefined();
});

it('should not remove $ properties from copy', function() {
var original = {$some: true};
var clone = {};

expect(shallowClearAndCopy(original, clone)).toBe(clone);
expect(clone.$some).toBe(original.$some);
});
});

it('should default to empty parameters', function() {
$httpBackend.expect('GET', 'URL').respond({});
Expand Down