Closed jaydenseric closed 3 years ago
Maybe keep a Set
of all objects encountered, and do a check if the object being recursed is in the set before entering?
I guess arrays can be circular too, not just plain objects.
Progress can be tracked here:
https://github.com/jaydenseric/extract-files/compare/master...jaydenseric/work-in-progress
I've merged in the latest changes from master
branch, but I can't really remember what I was up to last year when I pushed the work in progress:
https://github.com/jaydenseric/extract-files/commit/617e51a0313c2654254465042e3fc2703d4f1848
The tests pass but I feel like there was more to be done, so when I get time I'll try to re-immerse in the problem.
This will cause an infinite loop in the recursion logic, ending with a
Maximum call stack size exceeded
error:Perhaps the recursion logic should somehow detect when it's revisiting a node that has already been visited, and bail on further recursion? The cloned object should probably contain the same circular references as the original. I'm not sure yet the best way to do all this.
In the meantime, avoid providing
extractFiles
a value that may contain circular references.