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

Avoid stack overflow in filterFilter when using objects containing circular references #7751

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/ng/filter/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down