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

ObjectID.isValid should check that typeof toString === 'function' otherwise if it's not an object and doesn't have a toString then it would return false #27

Closed
niftylettuce opened this issue Jun 17, 2019 · 5 comments

Comments

@niftylettuce
Copy link
Collaborator

No description provided.

@niftylettuce
Copy link
Collaborator Author

e.g. if you pass an empty plain object to ObjectID.isValid it throws an uncaught exception.

@niftylettuce
Copy link
Collaborator Author

niftylettuce commented Jun 17, 2019

Specifically https://github.com/williamkapke/bson-objectid/blob/master/objectid.js#L98 should change to if (!objectid || (typeof objectid !== 'string' && (typeof objectid !== 'object' || typeof objectid.toString !== 'function')))

niftylettuce added a commit to cabinjs/parse-request that referenced this issue Jun 17, 2019
@williamkapke
Copy link
Collaborator

seems right. I'm happy to take a PR for it!

@niftylettuce
Copy link
Collaborator Author

roger, PR inbound

@niftylettuce
Copy link
Collaborator Author

@williamkapke see #28, I also added a test case as well.

let me know of any issues, or when a new version is published to npm.

thanks many! 👍

williamkapke added a commit that referenced this issue Jun 18, 2019
fix: fixed ObjectID.isValid logic (closes #27)
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

No branches or pull requests

2 participants