-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix: #186 avoid infinite recursion in filter method #187
Conversation
function filterKeys( | ||
obj: object, | ||
filters: string[], | ||
explored: Set<object> | null = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explored
is set to null by default, so it is not a mandatory parameter
// Original object should not be modified | ||
t.equal(body.username, "[email protected]"); | ||
t.equal(body.password, "nice try"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to ensure that we do the copy in the filterKeys
method, i.e. const _obj = { ...obj } as Record<string, object>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
* @param filters list of keys to filter | ||
* @param explored Set that contains already explored nodes, used internally | ||
*/ | ||
function filterKeys( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's been checked but it may be useful to check around the repo to see if we've done infinite recursion in the past and fix that up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't see any other instances in this repo. Do you mean in all the codebases from Raygun?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just one comment to address this issue as a whole in the repo if that hasn't been done yet :)
fix: #186 avoid infinite recursion in filter method
Description 📝
filterKeys
method uses recursion to explore the provided object, this can potentially cause infinite recursion and eventually throw the "Maximum call stack size exceeded" error.explored
parameter to the recursivefilterKeys
method, to check if the incoming object has already been explored or not.Type of change
Updates
explored: Set<object>
as parameter (it isnull
by default).Set
, remove from parent. Same as when applying filters.filterKeys
recursively, include the explored object in theSet
.One decision I had to make, is if the self-referenced object should be included in the output or not.
My decision to remove it from the output, is that we cannot apply filtering to the properties of the self-referenced object. Remember that we are doing a copy because we don't want to modify the original.
example of input from the test:
output would be:
After removing all filtered properties and self-referenced objects.
Test plan 🧪
Author to check 👓
Reviewer to check ✔️