Skip to content

Commit 97bb0a3

Browse files
committed
fix: Prevent extractQuadsRecursive infinite loop
1 parent 797a9e2 commit 97bb0a3

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/ucp/src/util/Util.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@ import { Store } from "n3";
66
* @param store
77
* @param subjectIRI
88
* @param existing IRIs that already have done the recursive search (IRIs in there must not be searched for again)
9-
* @returns
109
*/
11-
1210
export function extractQuadsRecursive(store: Store, subjectIRI: string, existing?: string[]): Store {
1311
const tempStore = new Store();
1412
const subjectIRIQuads = store.getQuads(subjectIRI, null, null, null);
1513

1614
tempStore.addQuads(subjectIRIQuads);
17-
const existingSubjects = existing ?? [subjectIRI];
15+
const existingSubjects = [ ...existing ?? [] ];
16+
existingSubjects.push(subjectIRI);
1817

1918
for (const subjectIRIQuad of subjectIRIQuads) {
2019
if (!existingSubjects.includes(subjectIRIQuad.object.id)) {
21-
tempStore.addQuads(extractQuadsRecursive(store, subjectIRIQuad.object.id, existingSubjects).getQuads(null, null, null, null));
20+
tempStore.addQuads(extractQuadsRecursive(store, subjectIRIQuad.object.id, existingSubjects)
21+
.getQuads(null, null, null, null));
2222
}
2323
else {
2424
tempStore.addQuad(subjectIRIQuad);
2525
}
26-
existingSubjects.push(subjectIRIQuad.object.id);
2726
}
2827
return tempStore;
29-
}// instantiated policy consisting of one agreement and one rule
30-
28+
}

0 commit comments

Comments
 (0)