Skip to content

Commit 4eb74a2

Browse files
committed
fix JSON to match native browser behavior
1 parent 955e8d9 commit 4eb74a2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/JSON.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ function toJsonArray(buf, obj, pretty, stack) {
128128
var childPretty = pretty ? pretty + " " : false;
129129
var keys = [];
130130
for(var k in obj) {
131-
if (obj[k] === undefined)
132-
continue;
133-
keys.push(k);
131+
if (obj.hasOwnProperty(k) && obj[k] !== undefined) {
132+
keys.push(k);
133+
}
134134
}
135135
keys.sort();
136136
for ( var keyIndex = 0; keyIndex < keys.length; keyIndex++) {

test/JsonSpec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ describe('json', function(){
7878
expect(angular.toJson(obj)).toEqual('{"$a":"a"}');
7979
});
8080

81-
it('should serialize inherited properties', function() {
81+
it('should NOT serialize inherited properties', function() {
82+
// This is what native Browser does
8283
var obj = inherit({p:'p'});
8384
obj.a = 'a';
84-
expect(angular.toJson(obj)).toEqual('{"a":"a","p":"p"}');
85+
expect(angular.toJson(obj)).toEqual('{"a":"a"}');
8586
});
8687

8788
it('should serialize same objects multiple times', function() {

0 commit comments

Comments
 (0)