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

toNumberPreprocessor converts empty string to 0 #40

Closed
Gambitier opened this issue Feb 26, 2023 · 1 comment · Fixed by #41
Closed

toNumberPreprocessor converts empty string to 0 #40

Gambitier opened this issue Feb 26, 2023 · 1 comment · Fixed by #41

Comments

@Gambitier
Copy link

Gambitier commented Feb 26, 2023

javascript converts empty string to 0. So if the this preprocessor is applied for number and if input is empty string then after transformation we receive value 0 which is number and hence zod doesn't throw any error

console.log(+''); // 0

if (typeof value === 'string' && !isNaN(+value)) {
return +value
}

@lokankr
Copy link
Contributor

lokankr commented Mar 1, 2023

Thank you for the report! This has been fixed and v2.0.0 has been released.

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

Successfully merging a pull request may close this issue.

2 participants