fix(drizzle-orm): is() crash on objects with null prototype#5625
Open
markacola wants to merge 1 commit into
Open
fix(drizzle-orm): is() crash on objects with null prototype#5625markacola wants to merge 1 commit into
markacola wants to merge 1 commit into
Conversation
Object.getPrototypeOf() returns null for objects created with Object.create(null). Without optional chaining, accessing .constructor on null throws a TypeError. This affects insert and update operations when a user passes an Object.create(null)-based value (e.g. for a JSON column), since the query builder calls is(colValue, SQL) on each value.
07bb13c to
570c97b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds optional chaining (
?.) to theObject.getPrototypeOf(value)call in theis()function in entity.ts.Why
Object.getPrototypeOf()returnsnullfor objects created withObject.create(null). Without optional chaining, accessing.constructoronnullthrows:This affects insert and update operations when a user passes an
Object.create(null)-based value (e.g. a JSON column value), because the query builder callsis(colValue, SQL)on each column value:Changes
Object.getPrototypeOf(value).constructortoObject.getPrototypeOf(value)?.constructoron line 29.is()returnsfalse(instead of throwing) forObject.create(null)valuesObject.create(null)objectObject.create(null)objectAll 3 tests produce
TypeError: Cannot read properties of null (reading 'constructor')without the fix.