From 7810393eb54dc94dcaeaebe51007cfd3371fce53 Mon Sep 17 00:00:00 2001 From: Tim Schlechter Date: Mon, 9 Jun 2014 13:42:28 +0200 Subject: [PATCH] Avoid stack overflow in filterFilter when using objects containing circular references --- src/ng/filter/filter.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index e662392d8dbf..b5811a0a68ee 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -151,10 +151,19 @@ function filterFilter() { } } - var search = function(obj, text){ + var search = function(obj, text, processed){ if (typeof text == 'string' && text.charAt(0) === '!') { - return !search(obj, text.substr(1)); + return !search(obj, text.substr(1), processed); } + + // Avoid stack overflows in case of circuler references in obj + processed = processed || []; + if (processed.indexOf(obj) !== -1) { + return false; + } else { + processed.push(obj); + } + switch (typeof obj) { case "boolean": case "number": @@ -166,7 +175,7 @@ function filterFilter() { return comparator(obj, text); default: for ( var objKey in obj) { - if (objKey.charAt(0) !== '$' && search(obj[objKey], text)) { + if (objKey.charAt(0) !== '$' && search(obj[objKey], text, processed)) { return true; } } @@ -175,7 +184,7 @@ function filterFilter() { return false; case "array": for ( var i = 0; i < obj.length; i++) { - if (search(obj[i], text)) { + if (search(obj[i], text, processed)) { return true; } }