fix: pass options object instead of boolean true to isJSON validator#18220
fix: pass options object instead of boolean true to isJSON validator#18220mixelburg wants to merge 1 commit into
Conversation
validator.js v13+ expects isJSON(str, options) where options is an
object. When a model defines `validate: { isJSON: true }`, Sequelize
previously passed `true` directly to the validator function, causing
a TypeError. Now it passes `{}` (empty options object) instead.
Fixes sequelize#18141
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated the instance validator to handle Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
| validatorArgs = []; | ||
| } else if (validatorType === 'isJSON' && validatorArgs === true) { | ||
| // validator.js v13+ expects an options object for isJSON, not a boolean | ||
| validatorArgs = [{}]; |
There was a problem hiding this comment.
Can it be an empty array or does it need an object?
There was a problem hiding this comment.
Don't forget to add regression tests in our unit test suites :)
Summary
Fixes a regression where
validate: { isJSON: true }fails with validator.js v13+.The
validator.isJSON(str, options)function now expectsoptionsto be an object, not a boolean. When a model setsisJSON: true, Sequelize extractedtrueas the validator argument and calledvalidator.isJSON(value, true), which throws because validator.js v13+ treatstrueas an invalid options argument.Changes
_extractValidatorArgs()forisJSON: when the validator arg is booleantrue, pass{}(empty options object) instead.Test plan
isImmutable,isLocalizedValidator).Related
Summary by CodeRabbit
Release Notes