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

fix: fixed error finding refs in an object with a length property #129

Conversation

argos83
Copy link
Contributor

@argos83 argos83 commented Dec 14, 2017

Hi! we bumped into this error (our library depends on a third-party library that depends on json-refs).

json-refs fail to traverse through an object that contains a length property, because of a wrong usage of lodash (see this).

We found the bug when objects like the following took a very long time to be processed:

{ "someObject": { "value": "hi", "length": 1000000} }

The issue was on this line, lodash's each on an object like someObject in the example above will invoke the callback 1000000 times with:

[undefined, 0], [undefined, 1], ..... [undefined, 999999]

instead of two times with:

["hi", "value"], ["length", 1000000]

as it assumes it is a collection because of the length property. To iterate key, values in an object forOwn should be used instead.

@@ -64,7 +64,7 @@
"vinyl-source-stream": "~1.1.0"
},
"dependencies": {
"commander": "^2.11.0",
"commander": "~2.11.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, commander 2.12 breaks two of your tests as it changes the way the output looks. It wasn't a trivial thing to fix, so I've pinned it to 2.11, and let you decide how you want to fix them.

Copy link

@BenSayers BenSayers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@martywins
Copy link

Any update on this?

@igorsechyn
Copy link

Can we please merge this? It is causing bugs in our codebase as well. Thank you.

@mauriedo
Copy link

Hello, any news on this? We are very keen to see this one fixed. Cheers!

@whitlockjc
Copy link
Owner

Do you know of any other places where _.each is used that should be turned into a _.forOwn?

@argos83
Copy link
Contributor Author

argos83 commented Dec 27, 2017

I did a search of .each throughout the codebase and found some others that might have the same issue, but I'm not familiarized with the code and didn't want to change them and possibly introduced a bug by doing so. Anyways, after fixing that single .each I could not longer reproduce the issue.

@BenSayers
Copy link

@whitlockjc the bug this PR is fixing is blocking my team, can we get it merged please?

@whitlockjc whitlockjc merged commit 23a2dd7 into whitlockjc:master Jan 3, 2018
whitlockjc added a commit that referenced this pull request Jan 3, 2018
@whitlockjc
Copy link
Owner

[email protected] was just released with these changes. Thanks for the PR.

@argos83
Copy link
Contributor Author

argos83 commented Jan 3, 2018

🎉 Thanks!

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

Successfully merging this pull request may close these issues.

6 participants