Skip to content

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

Merged
smarcet merged 3 commits intomasterfrom
fix/sponsor-form-desc-validation
Feb 10, 2026
Merged

fix: sponsor form description/instructions validation for html#775
smarcet merged 3 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 accept and validate HTML-formatted content across sponsor forms and templates.
  • Improvements
    • Rich-text editor input is normalized before saving to ensure consistent, trimmed HTML and more reliable validation.
  • Tests
    • Updated tests to cover the new normalization and HTML-focused validation behavior.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Add an HTML-normalizing validator and replace plain-string required validations with an HTML-aware validator across rich-text inputs and several form validation schemas; introduce normalizeHtmlString and wire it into the editor and yup utilities.

Changes

Cohort / File(s) Summary
Validation utility
src/utils/yup.js
Added requiredHTMLValidation() that transforms values 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
Added normalizeHtmlString implementation and updated tests (renamed from normalizeJoditEmpty).
Rich-text input
src/components/inputs/formik-text-editor.js
Replaced normalizeJoditEmpty with normalizeHtmlString when setting Formik field values.
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 validations from requiredStringValidation() to requiredHTMLValidation() and updated imports accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇✨ I nibble tags and tidy the string,
I trim the empty bits that silence brings.
From editor hop to validator bright,
Clean HTML dances into the night.

🚥 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 'fix: sponsor form description/instructions validation for html' directly and specifically describes the main change: replacing string validation with HTML validation for form fields across multiple sponsor form 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

No actionable comments were generated in the recent review. 🎉

Tip

We've launched Issue Planner and it is currently in beta. Please try it out and share your feedback on Discord!


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.

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.

LGTM

@smarcet
Copy link

smarcet commented Feb 10, 2026

LGTM

@smarcet smarcet merged commit 69badb1 into master Feb 10, 2026
9 checks passed
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