Skip to content

fix : added max length guard on question and answer fields in ValidateQuestions - #1548

Open
tmdeveloper007 wants to merge 5 commits into
Canopus-Labs:mainfrom
tmdeveloper007:#1543
Open

fix : added max length guard on question and answer fields in ValidateQuestions#1548
tmdeveloper007 wants to merge 5 commits into
Canopus-Labs:mainfrom
tmdeveloper007:#1543

Conversation

@tmdeveloper007

@tmdeveloper007 tmdeveloper007 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary of What Has Been Done

Added max length constraints to question (5000 chars) and answer (10000 chars) fields in backend/Input_validators/ValidateQuestions.js. Previously z.string().min(1, ...) was used without any .max() guard.

Changes Made

Modified backend/Input_validators/ValidateQuestions.js:

  • addQuestionToSessionSchema.questions[].question: added .max(5000, "Question must be at most 5000 characters")
  • addQuestionToSessionSchema.questions[].answer: added .max(10000, "Answer must be at most 10000 characters")

Impact it Made

  • Prevents excessively long question/answer strings from being stored
  • Consistent with the flashcard validator which already has these limits
  • Protects MongoDB storage from unbounded document sizes

Closes #1543

**Note: Please assign this PR to the tmdeveloper007 account.

Summary

  • Add maximum length validation to question and answer fields.
  • Limit question to 5,000 characters.
  • Limit answer to 10,000 characters.
  • Retain required-field validation.

Ready to merge.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d5908d1d-e2d2-411d-a1fb-debccf2eaca3

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba01aa and 4d4b836.

📒 Files selected for processing (1)
  • backend/Input_validators/ValidateQuestions.js

📝 Walkthrough

Walkthrough

The question session validation schema now limits question text to 5,000 characters and answer text to 10,000 characters. Required-field validation remains unchanged.

Changes

Question validation

Layer / File(s) Summary
Add question and answer length constraints
backend/Input_validators/ValidateQuestions.js
addQuestionToSessionSchema now rejects question text longer than 5,000 characters and answer text longer than 10,000 characters, with specific validation messages.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested reviewers: dev1822

🚥 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 clearly identifies the max-length guards added to the question and answer fields.
Linked Issues check ✅ Passed The changes implement the linked issue requirements for 5,000-character questions and 10,000-character answers.
Out of Scope Changes check ✅ Passed The changes are limited to the requested validation guards in ValidateQuestions.js.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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.

fix : add max length guard on question and answer fields in ValidateQuestions

1 participant