Fixed: crash in - CPArray/CPDictionary description containing self referential JS object.

Without this fix, certain JS contents could cause `- CPDictionary description` and `- CPArray description` to crash.

This change limits how deeply the description code will recurse before returning a default "…" description.
This commit is contained in:
Alexander Ljungberg
2013-06-13 20:14:22 +01:00
parent 22905745f1
commit e59389b0dd
5 changed files with 41 additions and 5 deletions
+8 -1
View File
@@ -37,6 +37,8 @@ CPBinarySearchingFirstEqual = 1 << 8;
CPBinarySearchingLastEqual = 1 << 9;
CPBinarySearchingInsertionIndex = 1 << 10;
var CPArrayMaxDescriptionRecursion = 10;
var concat = Array.prototype.concat,
join = Array.prototype.join,
push = Array.prototype.push;
@@ -874,6 +876,11 @@ var concat = Array.prototype.concat,
Returns a human readable description of this array and it's elements.
*/
- (CPString)description
{
return [self _descriptionWithMaximumDepth:CPArrayMaxDescriptionRecursion];
}
- (CPString)_descriptionWithMaximumDepth:(int)maximumDepth
{
var index = 0,
count = [self count],
@@ -887,7 +894,7 @@ var concat = Array.prototype.concat,
var object = [self objectAtIndex:index];
// NOTE: replace(/^/mg, " ") inserts 4 spaces at the beginning of every line
description += CPDescriptionOfObject(object).replace(/^/mg, " ");
description += CPDescriptionOfObject(object, maximumDepth).replace(/^/mg, " ");
if (index < count - 1)
description += ",\n";