From 1b21c50ff1b0ed0bc204bad95dc7877d71f0f234 Mon Sep 17 00:00:00 2001 From: Thomas Belin Date: Tue, 7 Jan 2014 16:09:37 +0100 Subject: [PATCH 1/4] fix(ngResource): restore shallowClearAndCopy properties fitlering condition Change the way properties are fitlered to create a resource from a JavaScript Object. in angular version >= 1.2.6 properties of a resource with a name beginning by a single '$' were fitlered from the created resource. Problem cames from the upgrade of the condition to filter properties that have a '$$' prefix in the shallow copy. See commit cb29632. Restore the behavior ngResource had in angular 1.2.5 and inferior versions. --- src/ngResource/resource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 055f089023ad..1ab31bf55609 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -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]; } } From 1fc6c9c833f71c8341d8649d4a84766ead9ca589 Mon Sep 17 00:00:00 2001 From: Thomas Belin Date: Wed, 8 Jan 2014 09:42:37 +0100 Subject: [PATCH 2/4] fix(Angular.js): restore shallowCopy properties fitlering condition in angular version >= 1.2.6 shallowCopy also filtered properties prefixed with a single `$` Problem cames from the upgrade of the condition to filter properties that have a '$$' prefix (See commit cb29632). Restore the behavior shallowCopy had in angular 1.2.5 and previous versions. --- src/Angular.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Angular.js b/src/Angular.js index 21ce1ff7282d..8e315fb77e76 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -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]; } } From 4d5c8690171c620ff247b8685c218546f1087555 Mon Sep 17 00:00:00 2001 From: Thomas Belin Date: Tue, 4 Feb 2014 15:26:32 +0100 Subject: [PATCH 3/4] fix(Angular.js): restore shallowCopy properties fitlering condition in angular version >= 1.2.6 shallowCopy also filtered properties prefixed with a single `$` Problem cames from the upgrade of the condition to filter properties that have a '$$' prefix (See commit cb29632). add unit tests for the shallowCopy in AngularSpec --- test/AngularSpec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 7fe65f4c8051..76bc05846ded 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -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() { From 074b5bd4ed43ef57145aaeda42b968c4559289e7 Mon Sep 17 00:00:00 2001 From: Thomas Belin Date: Tue, 4 Feb 2014 15:33:50 +0100 Subject: [PATCH 4/4] fix(ngResource): restore shallowClearAndCopy properties fitlering condition Change the way properties are fitlered to create a resource from a JavaScript Object. in angular version >= 1.2.6 properties of a resource with a name beginning by a single '$' were fitlered from the created resource. Problem cames from the upgrade of the condition to filter properties that have a '$$' prefix in the shallow copy. See commit cb29632. add the unit tests for shallowClearAndCopy function --- test/ngResource/resourceSpec.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index 08c27a0f715b..9906cf251b9c 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -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({});