mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-23 18:00:26 +00:00
Updated toJson() to not serialize window/document objects.
The reason to void these to objects is that they cause all sorts of problems like exceptions being thrown and infinite loops occuring when we iterate over object properties.
This commit is contained in:
parent
fe8353bc5e
commit
b7027b9d87
2 changed files with 20 additions and 2 deletions
14
src/JSON.js
14
src/JSON.js
|
|
@ -22,8 +22,18 @@ function fromJson(json) {
|
|||
angular['toJson'] = toJson;
|
||||
angular['fromJson'] = fromJson;
|
||||
|
||||
function toJsonArray(buf, obj, pretty, stack){
|
||||
if (typeof obj == "object") {
|
||||
function toJsonArray(buf, obj, pretty, stack) {
|
||||
if (isObject(obj)) {
|
||||
if (obj === window) {
|
||||
buf.push('WINDOW');
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj === document) {
|
||||
buf.push('DOCUMENT');
|
||||
return;
|
||||
}
|
||||
|
||||
if (includes(stack, obj)) {
|
||||
buf.push("RECURSION");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -92,6 +92,14 @@ describe('json', function(){
|
|||
it('should not serialize undefined values', function() {
|
||||
expect(angular.toJson({A:undefined})).toEqual('{}');
|
||||
});
|
||||
|
||||
it('should not serialize $window object', function() {
|
||||
expect(toJson(window)).toEqual('WINDOW');
|
||||
});
|
||||
|
||||
it('should not serialize $document object', function() {
|
||||
expect(toJson(document)).toEqual('DOCUMENT');
|
||||
});
|
||||
|
||||
it('should parse floats', function() {
|
||||
expect(fromJson("{value:2.55, name:'misko'}")).toEqual({value:2.55, name:'misko'});
|
||||
|
|
|
|||
Loading…
Reference in a new issue