From e134a8335f5ee7d2e81034ed93f3e465cb14573f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 17 Aug 2011 12:21:43 -0700 Subject: [PATCH] fix(filter): make json filter ignore private properties --- src/JSON.js | 2 +- src/filters.js | 3 +-- test/AngularSpec.js | 6 ------ test/JsonSpec.js | 4 ++++ 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/JSON.js b/src/JSON.js index 1dc5cc033dfc..7fdbf1a1647e 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -126,7 +126,7 @@ function toJsonArray(buf, obj, pretty, stack) { var childPretty = pretty ? pretty + " " : false; var keys = []; for(var k in obj) { - if (obj.hasOwnProperty(k) && obj[k] !== undefined) { + if (k!='this' && k!='$parent' && k.substring(0,2) != '$$' && obj.hasOwnProperty(k) && obj[k] !== undefined) { keys.push(k); } } diff --git a/src/filters.js b/src/filters.js index 6a136f929463..c5d886eac079 100644 --- a/src/filters.js +++ b/src/filters.js @@ -254,7 +254,6 @@ var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/, OPERA_TOSTRING_PATTERN = /^[\d].*Z$/, NUMBER_STRING = /^\d+$/; - /** * @workInProgress * @ngdoc filter @@ -409,7 +408,7 @@ angularFilter.date = function(date, format) { */ angularFilter.json = function(object) { this.$element.addClass("ng-monospace"); - return toJson(object, true); + return toJson(object, true, /^(\$|this$)/); }; diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 9f77d3ea0175..9a1a20c77e8a 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -514,12 +514,6 @@ describe('angular', function(){ expect(angular.scope().$service('svc2')).toEqual('svc2-svc1'); }); - it('should inject infered dependencies when $inject is missing', function() { - angular.service('svc1', function() { return 'svc1'; }); - angular.service('svc2', function(svc1) { return 'svc2-' + svc1; }); - expect(angular.scope().$service('svc2')).toEqual('svc2-svc1'); - }); - it('should eagerly instantiate a service if $eager is true', function() { var log = []; angular.service('svc1', function() { log.push('svc1'); }, {$eager: true}); diff --git a/test/JsonSpec.js b/test/JsonSpec.js index d9b245f932d1..b0bb15bca309 100644 --- a/test/JsonSpec.js +++ b/test/JsonSpec.js @@ -11,6 +11,10 @@ describe('json', function(){ expect(toJson("a \t \n \r b \\")).toEqual('"a \\t \\n \\r b \\\\"'); }); + it('should not serialize $$properties', function(){ + expect(toJson({$$some:'value', 'this':1, '$parent':1}, false)).toEqual('{}'); + }); + it('should serialize strings with escaped characters', function() { expect(toJson("7\\\"7")).toEqual("\"7\\\\\\\"7\""); });