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

Commit e134a83

Browse files
mheveryIgorMinar
authored andcommitted
fix(filter): make json filter ignore private properties
1 parent 8ee32a7 commit e134a83

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

src/JSON.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function toJsonArray(buf, obj, pretty, stack) {
126126
var childPretty = pretty ? pretty + " " : false;
127127
var keys = [];
128128
for(var k in obj) {
129-
if (obj.hasOwnProperty(k) && obj[k] !== undefined) {
129+
if (k!='this' && k!='$parent' && k.substring(0,2) != '$$' && obj.hasOwnProperty(k) && obj[k] !== undefined) {
130130
keys.push(k);
131131
}
132132
}

src/filters.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/,
254254
OPERA_TOSTRING_PATTERN = /^[\d].*Z$/,
255255
NUMBER_STRING = /^\d+$/;
256256

257-
258257
/**
259258
* @workInProgress
260259
* @ngdoc filter
@@ -409,7 +408,7 @@ angularFilter.date = function(date, format) {
409408
*/
410409
angularFilter.json = function(object) {
411410
this.$element.addClass("ng-monospace");
412-
return toJson(object, true);
411+
return toJson(object, true, /^(\$|this$)/);
413412
};
414413

415414

test/AngularSpec.js

-6
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,6 @@ describe('angular', function(){
514514
expect(angular.scope().$service('svc2')).toEqual('svc2-svc1');
515515
});
516516

517-
it('should inject infered dependencies when $inject is missing', function() {
518-
angular.service('svc1', function() { return 'svc1'; });
519-
angular.service('svc2', function(svc1) { return 'svc2-' + svc1; });
520-
expect(angular.scope().$service('svc2')).toEqual('svc2-svc1');
521-
});
522-
523517
it('should eagerly instantiate a service if $eager is true', function() {
524518
var log = [];
525519
angular.service('svc1', function() { log.push('svc1'); }, {$eager: true});

test/JsonSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ describe('json', function(){
1111
expect(toJson("a \t \n \r b \\")).toEqual('"a \\t \\n \\r b \\\\"');
1212
});
1313

14+
it('should not serialize $$properties', function(){
15+
expect(toJson({$$some:'value', 'this':1, '$parent':1}, false)).toEqual('{}');
16+
});
17+
1418
it('should serialize strings with escaped characters', function() {
1519
expect(toJson("7\\\"7")).toEqual("\"7\\\\\\\"7\"");
1620
});

0 commit comments

Comments
 (0)