Skip to content

Commit ee89d49

Browse files
authored
Merge pull request #100 from bfritscher/copilot/fix-9c07b1d8-79eb-4541-bda0-181b722d9688
Fix infinite recursion in SearchResultItemNestedDisplay.extractValue causing stack overflow
2 parents 9d074e1 + 275e366 commit ee89d49

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/components/search/SearchResultItemNestedDisplay.vue

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,42 @@ const sortedKeys = computed(() => {
7474
.concat(keys.filter((key) => !props.includeFields.includes(key)));
7575
});
7676
77-
function extractValue(item: any): any {
77+
function extractValue(item: any, depth = 0, visited = new WeakSet()): any {
78+
// Prevent infinite recursion with depth limit
79+
if (depth > 10) {
80+
return '[Max depth reached]';
81+
}
82+
83+
// Handle primitive values
84+
if (item === null || item === undefined) {
85+
return item;
86+
}
87+
if (typeof item !== 'object') {
88+
return item;
89+
}
90+
91+
// Prevent circular references
92+
if (visited.has(item)) {
93+
return '[Circular reference]';
94+
}
95+
visited.add(item);
96+
7897
if (Array.isArray(item)) {
79-
return item.map((subitem: any) => extractValue(subitem));
98+
return item.map((subitem: any) => extractValue(subitem, depth + 1, visited));
8099
}
100+
81101
if (
82102
Object.prototype.hasOwnProperty.call(item, 'value') &&
83103
Object.prototype.hasOwnProperty.call(item, 'matchLevel')
84104
) {
85105
return item.value;
86106
}
107+
87108
const values: Record<string, any> = {};
88109
for (const key in item) {
89-
values[key] = extractValue(item[key]);
110+
if (Object.prototype.hasOwnProperty.call(item, key)) {
111+
values[key] = extractValue(item[key], depth + 1, visited);
112+
}
90113
}
91114
return values;
92115
}

0 commit comments

Comments
 (0)