Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle circular references #14

Closed
jaydenseric opened this issue Jul 22, 2020 · 3 comments
Closed

Handle circular references #14

jaydenseric opened this issue Jul 22, 2020 · 3 comments
Labels

Comments

@jaydenseric
Copy link
Owner

This will cause an infinite loop in the recursion logic, ending with a Maximum call stack size exceeded error:

const a = {};
a.b = a;
extractFiles(a)

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.

@jaydenseric
Copy link
Owner Author

Maybe keep a Set of all objects encountered, and do a check if the object being recursed is in the set before entering?

@jaydenseric
Copy link
Owner Author

I guess arrays can be circular too, not just plain objects.

@jaydenseric
Copy link
Owner Author

Progress can be tracked here:

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:

617e51a

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant