aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Angular.js2
-rw-r--r--src/ngResource/resource.js2
-rw-r--r--test/AngularSpec.js23
-rw-r--r--test/ngResource/resourceSpec.js43
4 files changed, 67 insertions, 3 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 21ce1ff7..8e315fb7 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];
}
}
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index 055f0890..1ab31bf5 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];
}
}
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index 7fe65f4c..117e8fb0 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -190,7 +190,7 @@ 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 = {};
@@ -198,6 +198,27 @@ describe('angular', function() {
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() {
diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js
index 08c27a0f..1c0b73b9 100644
--- a/test/ngResource/resourceSpec.js
+++ b/test/ngResource/resourceSpec.js
@@ -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() {
$httpBackend.expect('GET', 'URL').respond({});
$resource('URL').query();