Skip to content

Commit

Permalink
fix(ngResource): don't filter "$"-prefixed properties from ngResource…
Browse files Browse the repository at this point in the history
… requests/responses

ngResource no longer filters properties prefixed with a single "$" character from requests or
responses, correcting a regression introduced in 1.2.6 (cb29632).

Closes angular#5666
Closes angular#6080
Closes angular#6033
  • Loading branch information
Thomas Belin authored and caitp committed Feb 4, 2014
1 parent 0da6cc9 commit 5dc625f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
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
23 changes: 22 additions & 1 deletion test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,35 @@ describe('angular', function() {
expect(copy.key).toBe(original.key);
});

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

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

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

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

it('should omit properties from prototype chain', function() {
var original, clone = {};
function Func() {};
Func.prototype.hello = "world";

original = new Func();
original.goodbye = "world";

expect(shallowCopy(original, clone)).toBe(clone);
expect(clone.hello).toBeUndefined();
expect(clone.goodbye).toBe("world");
});
});

describe('elementHTML', function() {
Expand Down
42 changes: 42 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,48 @@ describe("resource", 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 omit "$$"-prefixed properties', function() {
var original = {$$some: true, $$: true};
var clone = {};

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


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

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


it('should omit properties from prototype chain', function() {
var original, clone = {};
function Func() {};
Func.prototype.hello = "world";

original = new Func();
original.goodbye = "world";

expect(shallowClearAndCopy(original, clone)).toBe(clone);
expect(clone.hello).toBeUndefined();
expect(clone.goodbye).toBe("world");
});
});

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

0 comments on commit 5dc625f

Please sign in to comment.