mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
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 (cb29632a) which caused shallowCopy and
shallowClearAndCopy to ignore properties prefixed with a single "$".
Closes #5666
Closes #6080
Closes #6033
This commit is contained in:
parent
0da6cc9118
commit
d2e4e49986
4 changed files with 67 additions and 3 deletions
|
|
@ -772,7 +772,7 @@ function shallowCopy(src, dst) {
|
||||||
for(var key in src) {
|
for(var key in src) {
|
||||||
// shallowCopy is only ever called by $compile nodeLinkFn, which has control over 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
|
// 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];
|
dst[key] = src[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ function shallowClearAndCopy(src, dst) {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var key in src) {
|
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];
|
dst[key] = src[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ describe('angular', function() {
|
||||||
expect(copy.key).toBe(original.key);
|
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 original = {$$some: true, $$: true};
|
||||||
var clone = {};
|
var clone = {};
|
||||||
|
|
||||||
|
|
@ -198,6 +198,27 @@ describe('angular', function() {
|
||||||
expect(clone.$$some).toBeUndefined();
|
expect(clone.$$some).toBeUndefined();
|
||||||
expect(clone.$$).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() {
|
describe('elementHTML', function() {
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,49 @@ 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() {
|
it('should default to empty parameters', function() {
|
||||||
$httpBackend.expect('GET', 'URL').respond({});
|
$httpBackend.expect('GET', 'URL').respond({});
|
||||||
$resource('URL').query();
|
$resource('URL').query();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue