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

Commit 7159b30

Browse files
author
Igor Minar
committed
Serialize only own properties to avoid infinite loops when serializing scopes (this)
1 parent 84b3a17 commit 7159b30

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/JSON.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function toJsonArray(buf, obj, pretty, stack){
7474
var childPretty = pretty ? pretty + " " : false;
7575
var keys = [];
7676
for(var k in obj) {
77-
if (k.indexOf('$$') === 0 || obj[k] === undefined)
77+
if (!obj.hasOwnProperty(k) || k.indexOf('$$') === 0 || obj[k] === undefined)
7878
continue;
7979
keys.push(k);
8080
}

test/JsonTest.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ JsonTest.prototype.testItShouldPreventRecursion = function () {
7474
assertEquals('{"a":"b","recursion":RECURSION}', angular.toJson(obj));
7575
};
7676

77+
JsonTest.prototype.testItShouldSerializeOnlyOwnProperties = function() {
78+
var parent = { p: 'p'};
79+
var child = { c: 'c'};
80+
child.__proto__ = parent;
81+
assertEquals('{"c":"c"}', angular.toJson(child));
82+
}
83+
7784
JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () {
7885
var obj = {a:'b'};
7986
assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj}));

0 commit comments

Comments
 (0)