-
Notifications
You must be signed in to change notification settings - Fork 254
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(NODE-3760): ObjectId.isValid string and byte length match #475
Conversation
…st cases, remove throw-deprecation flag
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
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 see that this check is only in the isValid method, what we discussed regarding the implementation when we triaged this is in the comment on the ticket:
what we need to do is add logic to catch this case in the constructor and then also add corresponding logic in the isValid check so that isValid uses the same criteria as the constructor to determine validity
@nbbeeken do you guys by any chance have some sort of kickoff notes about what is and isn't in scope for the implementation? because without unifying constructor logic with the validation logic we are just making a bandaid fix without actually improving the validation/constructor duality
Added retroactive kickoff notes; Grace's fix already addresses the user's specific issue in constructor, we're now syncing
|
@syz99 thanks for double checking! I am still wondering though if we can consolidate the validation logic so that we don't have to rely on duplicating the correct validation blocks in the isValid function; have we considered if there can be a general validation method that can be used in both places or even the approach of calling the constructor to create an ObjectId in the isValid function? |
👍 to the idea of removing duplicate logic when possible! @dariakp Are you wondering about replacing the entirety of the |
The former, try/catch around the call and return true/false accordingly; it's the most straightforward way to maintain parity given how the validation is split up; it'll be less ugly if we break out the overloads into separate functions down the road for the next major versions, but for now there aren't many options to make it pretty aside from the aforementioned one |
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.
Yay for less code and more consistency 🎉
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 - nice work!
Description
What is changing?
adds validation for string and byte length matching for new ObjectID's.
What is the motivation for this change?
bugs found with strings of char-length 12, but byte-length =/= 12.
Double check the following
npm run lint
script<type>(NODE-xxxx)<!>: <description>