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: bigint coerce crash #3822

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,11 @@ export interface ZodBigIntDef extends ZodTypeDef {
export class ZodBigInt extends ZodType<bigint, ZodBigIntDef, bigint> {
_parse(input: ParseInput): ParseReturnType<bigint> {
if (this._def.coerce) {
input.data = BigInt(input.data);
try {
input.data = BigInt(input.data);
} catch {
input.data = undefined;

Choose a reason for hiding this comment

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

Maybe here should return INVALID instate of undefined

Copy link
Author

Choose a reason for hiding this comment

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

That works and looks more correct 👍🏻

}
}
const parsedType = this._getType(input);
if (parsedType !== ZodParsedType.bigint) {
Expand Down
6 changes: 5 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,11 @@ export interface ZodBigIntDef extends ZodTypeDef {
export class ZodBigInt extends ZodType<bigint, ZodBigIntDef, bigint> {
_parse(input: ParseInput): ParseReturnType<bigint> {
if (this._def.coerce) {
input.data = BigInt(input.data);
try {
input.data = BigInt(input.data);
} catch {
input.data = undefined;

Choose a reason for hiding this comment

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

Maybe here should return INVALID instate of undefined

Copy link
Author

Choose a reason for hiding this comment

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

That works and looks more correct 👍🏻

}
}
const parsedType = this._getType(input);
if (parsedType !== ZodParsedType.bigint) {
Expand Down