Skip to content

fix: pass options object instead of boolean true to isJSON validator#18220

Open
mixelburg wants to merge 1 commit into
sequelize:mainfrom
mixelburg:fix/isJSON-validation
Open

fix: pass options object instead of boolean true to isJSON validator#18220
mixelburg wants to merge 1 commit into
sequelize:mainfrom
mixelburg:fix/isJSON-validation

Conversation

@mixelburg
Copy link
Copy Markdown

@mixelburg mixelburg commented Apr 30, 2026

Summary

Fixes a regression where validate: { isJSON: true } fails with validator.js v13+.

The validator.isJSON(str, options) function now expects options to be an object, not a boolean. When a model sets isJSON: true, Sequelize extracted true as the validator argument and called validator.isJSON(value, true), which throws because validator.js v13+ treats true as an invalid options argument.

Changes

  • Added special handling in _extractValidatorArgs() for isJSON: when the validator arg is boolean true, pass {} (empty options object) instead.

Test plan

  • The fix is minimal (3 lines added) and follows the existing pattern for other special-case validators (e.g., isImmutable, isLocalizedValidator).

Related

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed JSON validator configuration to ensure compatibility with newer validator.js library versions, improving the reliability of validation handling.

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
@mixelburg mixelburg requested a review from a team as a code owner April 30, 2026 22:29
@mixelburg mixelburg requested review from ephys and sdepold April 30, 2026 22:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9793276-7d45-4fab-bb6d-54106e93e802

📥 Commits

Reviewing files that changed from the base of the PR and between ab2c9ad and b2f21bb.

📒 Files selected for processing (1)
  • packages/core/src/instance-validator.js

📝 Walkthrough

Walkthrough

Updated the instance validator to handle isJSON validators configured with a boolean true value by converting it to an empty options object, ensuring compatibility with newer validator.js versions that expect an options object as the second parameter.

Changes

Cohort / File(s) Summary
isJSON Validator Compatibility
packages/core/src/instance-validator.js
Added logic to convert boolean true argument for isJSON validators into an empty options object ({}) to match updated validator.js API expectations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A JSON validator once cried,
"This boolean true has hurt my pride!"
But a clever fix came into play,
Converting booleans the proper way—
Now validation dances with glee! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: converting boolean true to an options object for the isJSON validator to work with validator.js v13+.
Linked Issues check ✅ Passed The PR directly addresses issue #18141 by fixing the isJSON validator to pass an options object instead of boolean true, meeting the core requirement to restore compatibility with validator.js v13+.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to fixing isJSON validation handling in the validator argument extraction, with no unrelated modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Member

@ephys ephys left a comment

Choose a reason for hiding this comment

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

Thank you for your PR!

validatorArgs = [];
} else if (validatorType === 'isJSON' && validatorArgs === true) {
// validator.js v13+ expects an options object for isJSON, not a boolean
validatorArgs = [{}];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can it be an empty array or does it need an object?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't forget to add regression tests in our unit test suites :)

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 this pull request may close these issues.

isJSON validation

2 participants