Skip to content

fix: sponsor form description/instructions validation for html#775

Open
santipalenque wants to merge 2 commits intomasterfrom
fix/sponsor-form-desc-validation
Open

fix: sponsor form description/instructions validation for html#775
santipalenque wants to merge 2 commits intomasterfrom
fix/sponsor-form-desc-validation

Conversation

@santipalenque
Copy link

@santipalenque santipalenque commented Feb 4, 2026

https://app.clickup.com/t/86b8b1nup

Summary by CodeRabbit

  • New Features
    • Form instructions and description fields now support HTML-formatted content across sponsor forms and templates.
  • Improvements
    • Editor input is normalized and sanitized before saving to ensure consistent, trimmed HTML content.
  • Tests
    • Test coverage updated to reflect the new normalization behavior.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds a HTML-normalizing required validator and replaces string-required validations with the new HTML-aware validator for several form fields and the rich-text editor normalization function.

Changes

Cohort / File(s) Summary
Validation utility
src/utils/yup.js
Added requiredHTMLValidation() which transforms input via normalizeHtmlString and marks the field required.
HTML normalization
src/utils/normalize-html-string/index.js, src/utils/normalize-html-string/__tests__/normalizeHtmlString.test.js
Renamed normalizeJoditEmptynormalizeHtmlString; tests updated to the new name.
Rich-text input
src/components/inputs/formik-text-editor.js
Replaced use of normalizeJoditEmpty with normalizeHtmlString when updating Formik state.
Form validation updates
src/pages/sponsors-global/form-templates/form-template-popup.js, src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js, src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.js, src/pages/sponsors/sponsor-forms-list-page/components/form-template/form-template-form.js
Switched instructions/description field validation from requiredStringValidation() to requiredHTMLValidation() and updated imports accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • smarcet

Poem

🐇✨ I nibble tags and tidy the string,
Trim whitespace neat — hear the form bells ring.
From editor hops to validator's light,
Clean inputs dance, all cozy and bright.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing string validation with HTML validation for sponsor form description/instructions fields across multiple components.
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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/sponsor-form-desc-validation

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/utils/yup.js`:
- Around line 90-104: The transform in requiredHTMLValidation currently strips
tags but leaves HTML entities like &nbsp; so strings like "<p>&nbsp;</p>" pass
validation; update the normalization to convert non-breaking spaces to regular
spaces before trimming—either modify stripHtmlTags or the transform in
requiredHTMLValidation to replace occurrences of "&nbsp;" and "&#160;" (or
convert \u00A0) with a normal space, then strip tags and call .trim(); ensure
you reference stripHtmlTags and requiredHTMLValidation so the transform returns
a truly empty string for content that only contains NBSPs.

@fntechgit fntechgit deleted a comment from coderabbitai bot Feb 4, 2026
src/utils/yup.js Outdated
.transform((value, originalValue) => {
// If the value is a string, strip HTML tags
if (typeof originalValue === "string") {
const strippedValue = stripHtmlTags(originalValue);
Copy link

Choose a reason for hiding this comment

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

Copy link

@smarcet smarcet left a comment

Choose a reason for hiding this comment

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

@santipalenque please review comments

@santipalenque santipalenque force-pushed the fix/sponsor-form-desc-validation branch from 97b2bdc to 5e468d2 Compare February 4, 2026 20:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/utils/yup.js`:
- Around line 90-105: The transform in requiredHTMLValidation currently strips
tags but leaves HTML entities like &nbsp; so strings of entities can pass
validation; update either stripHtmlTags or the transform callback in
requiredHTMLValidation to first normalize HTML entities to regular whitespace
(e.g., replace common entities such as &nbsp; and numeric entities like &#160;
or use a generic regex /&[^\s;]+;/g → ' ') before stripping tags and trimming,
ensuring entity-only content becomes empty and fails the required check.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/utils/normalize-html-string/index.js`:
- Around line 1-4: normalizeHtmlString currently checks
doc.body.textContent.length === 0 which treats whitespace and non-breaking
spaces as content; update the check to normalize whitespace by trimming and
replacing NBSPs (e.g., replace \u00A0 with regular space) and collapsing
whitespace before measuring length. Specifically, in normalizeHtmlString use new
DOMParser().parseFromString(textInput, "text/html") to get doc, compute a
normalizedText from doc.body.textContent by replacing \u00A0 with ' ',
collapsing consecutive whitespace to a single space and trimming, then return ""
if normalizedText.length === 0 otherwise return textInput.

Comment on lines +1 to 4
// removes html tags if contained text is empty
const normalizeHtmlString = (textInput) => {
const doc = new DOMParser().parseFromString(textInput, "text/html");
return doc.body.textContent.length === 0 ? "" : textInput;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Treat whitespace-only HTML as empty.

textContent.length === 0 will treat whitespace or &nbsp; as content, so required HTML validation can pass with visually empty input. Normalize whitespace before checking length.

🛠️ Proposed fix
-  return doc.body.textContent.length === 0 ? "" : textInput;
+  const text = doc.body.textContent.replace(/\u00a0/g, " ").trim();
+  return text.length === 0 ? "" : textInput;
🤖 Prompt for AI Agents
In `@src/utils/normalize-html-string/index.js` around lines 1 - 4,
normalizeHtmlString currently checks doc.body.textContent.length === 0 which
treats whitespace and non-breaking spaces as content; update the check to
normalize whitespace by trimming and replacing NBSPs (e.g., replace \u00A0 with
regular space) and collapsing whitespace before measuring length. Specifically,
in normalizeHtmlString use new DOMParser().parseFromString(textInput,
"text/html") to get doc, compute a normalizedText from doc.body.textContent by
replacing \u00A0 with ' ', collapsing consecutive whitespace to a single space
and trimming, then return "" if normalizedText.length === 0 otherwise return
textInput.

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.

2 participants