-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(record): handle non-function constructor field in isPlainObject #5098
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
base: main
Are you sure you want to change the base?
Conversation
| const ctor = o.constructor; | ||
| if (ctor === undefined) return true; | ||
|
|
||
| if (typeof ctor !== "function") return true; |
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.
Line 380 could replace line 378, instead of having both, since this check includes the case where ctor === undefined (since in that case typeof ctor is "undefined", which does not equal "function"). But the extra clarity doesn't hurt anything.
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.
You're suggestion is technically correct - line 380 (typeof ctor !== "function") would handle both cases since typeof undefined returns "undefined", not "function".
However, I'd keep both lines for clarity. The explicit undefined check makes the intent more obvious and doesn't hurt performance.
It's a style preference, and the current approach is more readable.
|
@colinhacks I believe this issue needs to be addressed. I would appreciate it if you could review the PR. 🙏 |
|
any updates on this? |
|
There are no additional changes, and we are awaiting the maintainer's approval. |
|
@colinhacks there's some other people with interest, would love to help out and get this merged if this is the desired fix. |
|
^^^ following up again, working around this isn't great |
Problem
z.record() schema fails to parse plain objects with non-function constructor field, throwing "Invalid input: expected record, received object" error.
Solution
Add type check in isPlainObject function to treat objects with non-function constructor as plain objects.
Tests
Closes #5066