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

Commit d2e4e49

Browse files
Thomas Belincaitp
Thomas Belin
authored andcommitted
fix(ngResource): don't filter "$"-prefixed properties from ngResource 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) which caused shallowCopy and shallowClearAndCopy to ignore properties prefixed with a single "$". Closes #5666 Closes #6080 Closes #6033
1 parent 0da6cc9 commit d2e4e49

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ function shallowCopy(src, dst) {
772772
for(var key in src) {
773773
// shallowCopy is only ever called by $compile nodeLinkFn, which has control over src
774774
// so we don't need to worry about using our custom hasOwnProperty here
775-
if (src.hasOwnProperty(key) && key.charAt(0) !== '$' && key.charAt(1) !== '$') {
775+
if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
776776
dst[key] = src[key];
777777
}
778778
}

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function shallowClearAndCopy(src, dst) {
3535
});
3636

3737
for (var key in src) {
38-
if (src.hasOwnProperty(key) && key.charAt(0) !== '$' && key.charAt(1) !== '$') {
38+
if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
3939
dst[key] = src[key];
4040
}
4141
}

test/AngularSpec.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,35 @@ describe('angular', function() {
190190
expect(copy.key).toBe(original.key);
191191
});
192192

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

197197
expect(shallowCopy(original, clone)).toBe(clone);
198198
expect(clone.$$some).toBeUndefined();
199199
expect(clone.$$).toBeUndefined();
200200
});
201+
202+
it('should copy "$"-prefixed properties from copy', function() {
203+
var original = {$some: true};
204+
var clone = {};
205+
206+
expect(shallowCopy(original, clone)).toBe(clone);
207+
expect(clone.$some).toBe(original.$some);
208+
});
209+
210+
it('should omit properties from prototype chain', function() {
211+
var original, clone = {};
212+
function Func() {};
213+
Func.prototype.hello = "world";
214+
215+
original = new Func();
216+
original.goodbye = "world";
217+
218+
expect(shallowCopy(original, clone)).toBe(clone);
219+
expect(clone.hello).toBeUndefined();
220+
expect(clone.goodbye).toBe("world");
221+
});
201222
});
202223

203224
describe('elementHTML', function() {

test/ngResource/resourceSpec.js

+43
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,49 @@ describe("resource", function() {
9494
});
9595

9696

97+
describe('shallow copy', function() {
98+
it('should make a copy', function() {
99+
var original = {key:{}};
100+
var copy = shallowClearAndCopy(original);
101+
expect(copy).toEqual(original);
102+
expect(copy.key).toBe(original.key);
103+
});
104+
105+
106+
it('should omit "$$"-prefixed properties', function() {
107+
var original = {$$some: true, $$: true};
108+
var clone = {};
109+
110+
expect(shallowClearAndCopy(original, clone)).toBe(clone);
111+
expect(clone.$$some).toBeUndefined();
112+
expect(clone.$$).toBeUndefined();
113+
});
114+
115+
116+
it('should copy "$"-prefixed properties from copy', function() {
117+
var original = {$some: true};
118+
var clone = {};
119+
120+
expect(shallowClearAndCopy(original, clone)).toBe(clone);
121+
expect(clone.$some).toBe(original.$some);
122+
});
123+
124+
125+
it('should omit properties from prototype chain', function() {
126+
var original, clone = {};
127+
function Func() {};
128+
Func.prototype.hello = "world";
129+
130+
original = new Func();
131+
original.goodbye = "world";
132+
133+
expect(shallowClearAndCopy(original, clone)).toBe(clone);
134+
expect(clone.hello).toBeUndefined();
135+
expect(clone.goodbye).toBe("world");
136+
});
137+
});
138+
139+
97140
it('should default to empty parameters', function() {
98141
$httpBackend.expect('GET', 'URL').respond({});
99142
$resource('URL').query();

0 commit comments

Comments
 (0)