-
Notifications
You must be signed in to change notification settings - Fork 480
feat: implement Story Block character limit validation and enhance error handling (#34304) #34525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This update introduces character limit validation for Story Block fields in the content management system. The validation checks if the character count exceeds a specified limit and logs warnings accordingly. Additionally, it enhances the to handle character limit errors, ensuring that relevant error messages are generated when limits are exceeded. Key changes include: - New method in to extract character count from Story Block JSON. - Updates to to validate character limits during content checks. - Modifications to and to manage character limit errors. - Added tests to ensure proper validation behavior for Story Block fields. This feature improves content integrity by enforcing character limits on Story Block fields, enhancing user experience and data consistency.
dotcms-integration/src/test/java/com/dotcms/contenttype/business/StoryBlockValidationTest.java
Show resolved
Hide resolved
dotcms-integration/src/test/java/com/dotcms/contenttype/business/StoryBlockValidationTest.java
Show resolved
Hide resolved
dotcms-integration/src/test/java/com/dotcms/contenttype/business/StoryBlockValidationTest.java
Outdated
Show resolved
Hide resolved
dotcms-integration/src/test/java/com/dotcms/contenttype/business/StoryBlockValidationTest.java
Outdated
Show resolved
Hide resolved
dotcms-integration/src/test/java/com/dotcms/contenttype/business/StoryBlockValidationTest.java
Outdated
Show resolved
Hide resolved
This update introduces improved error handling and validation for the DotBlockEditor component. Key changes include: - Added input to manage external error states. - Implemented and getters to provide detailed error feedback in the UI. - Enhanced the template to display error messages for character limits and required fields. - Introduced styling for error states in the editor wrapper. - Updated tests to cover new validation scenarios and ensure robust error handling. These enhancements improve user experience by providing clear feedback on content validation, ensuring data integrity in the editing process.
core-web/libs/block-editor/src/lib/components/dot-block-editor/dot-block-editor.component.scss
Outdated
Show resolved
Hide resolved
...ibs/edit-content/src/lib/components/dot-edit-content-form/dot-edit-content-form.component.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Implements character-limit validation for Story Block / Block Editor fields across the Angular edit-content UI and backend contentlet validation flow, aiming to prevent saving content that exceeds configured limits and to improve validation UX and error reporting.
Changes:
- Frontend: adds real-time char limit + required validation UI/logic to the block editor, integrates a custom “required” validator for Block Editor fields, and propagates field error state to the editor.
- Backend: adds a CHAR_LIMIT validation code/path to
DotContentletValidationException, maps it to localized error messages, and enforces char limit duringvalidateContentlet. - Tests & tooling/docs: expands integration/unit test coverage and adds AI tooling configuration/docs updates.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
dotcms-integration/src/test/java/com/dotcms/contenttype/test/StoryBlockUtilTest.java |
Adds unit tests for StoryBlockUtil.getCharCount and refines test docs. |
dotcms-integration/src/test/java/com/dotcms/contenttype/business/StoryBlockValidationTest.java |
Adds integration tests for Story Block charLimit behavior during checkin. |
dotCMS/src/main/webapp/WEB-INF/messages/Language.properties |
Adds localized message for char limit exceeded. |
dotCMS/src/main/java/com/dotmarketing/util/importer/ImportLineValidationCodes.java |
Adds CHAR_LIMIT_EXCEEDED validation code. |
dotCMS/src/main/java/com/dotmarketing/portlets/fileassets/business/FileAssetValidationException.java |
Extends constructor support to carry char limit metadata. |
dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/DotContentletValidationException.java |
Adds char limit validation key, tracking map, builder support, and helpers. |
dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/ajax/ContentletAjax.java |
Surfaces char limit validation errors in AJAX save responses. |
dotCMS/src/main/java/com/dotcms/exception/ExceptionUtil.java |
Maps char limit validation errors into structured ValidationErrors. |
dotCMS/src/main/java/com/dotcms/contenttype/util/StoryBlockUtil.java |
Adds getCharCount helper for extracting TipTap attrs.charCount. |
dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java |
Enforces Story Block charLimit during validateContentlet. |
core-web/libs/edit-content/src/lib/utils/validators.ts |
Adds custom blockEditorRequiredValidator() and JSON traversal helpers. |
core-web/libs/edit-content/src/lib/utils/validators.spec.ts |
Adds unit tests for the new block editor required validator. |
core-web/libs/edit-content/src/lib/fields/shared/base-wrapper-field.ts |
Adjusts required detection to prefer field definition over validator inference. |
core-web/libs/edit-content/src/lib/fields/dot-edit-content-block-editor/dot-edit-content-block-editor.component.html |
Passes hasFieldError into the block editor and moves hint to label. |
core-web/libs/edit-content/src/lib/components/dot-edit-content-form/dot-edit-content-form.component.ts |
Uses custom required validator for Block Editor fields. |
core-web/libs/block-editor/src/lib/components/dot-block-editor/dot-block-editor.component.ts |
Adds error-state inputs/getters and sets/clears charLimitExceeded form errors. |
core-web/libs/block-editor/src/lib/components/dot-block-editor/dot-block-editor.component.html |
Shows required/char-limit messages and applies error styling. |
core-web/libs/block-editor/src/lib/components/dot-block-editor/dot-block-editor.component.scss |
Adds error outline + footer layout styling. |
core-web/libs/block-editor/src/lib/components/dot-block-editor/dot-block-editor.component.spec.ts |
Adds unit tests for new error/validation behavior. |
core-web/CLAUDE.md |
Markdown formatting tweaks. |
core-web/AGENTS.md |
Markdown formatting tweaks. |
core-web/.mcp.json |
Adds Nx MCP server configuration. |
core-web/.gemini/settings.json |
Adds Gemini MCP server configuration. |
.cursor/agents/typescript-unit-testing.md |
Adds TypeScript unit testing agent guide. |
dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java
Show resolved
Hide resolved
...rc/main/java/com/dotmarketing/portlets/fileassets/business/FileAssetValidationException.java
Show resolved
Hide resolved
dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java
Show resolved
Hide resolved
This commit refines the DotBlockEditor component by updating the HTML structure and CSS styles for error messages. Key changes include: - Replaced the footer error container with a more flexible layout using PrimeFlex classes. - Updated error message styling to enhance visibility and consistency. - Removed redundant CSS rules related to the footer, streamlining the component's styles. These adjustments improve the user interface and ensure better alignment with the overall design standards.
|
Semgrep found 1
Risk: Affected versions of @angular/compiler and @angular/core are vulnerable to Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'). Angular's template compiler fails to classify the Fix: Upgrade this library to at least version 20.3.16 at core/core-web/yarn.lock:512. Reference(s): GHSA-jrmj-c5cx-3cw6, CVE-2026-22610 If this is a critical or high severity finding, please also link this issue in the #security channel in Slack. |
Summary
Implements comprehensive character limit validation for Story Block fields with real-time feedback, enhanced error handling in the block editor component, and improved test coverage for validation scenarios.
This ensures content editors receive immediate feedback when exceeding configured character limits and prevents invalid content from being saved.
New Edit Content
CleanShot.2026-02-05.at.11.59.04.mp4
Old Edit Content
CleanShot.2026-02-06.at.12.55.18.mp4
Changes Made
Frontend (Angular/TypeScript)
Block Editor Component (
core-web/libs/block-editor/src/lib/components/dot-block-editor/)Enhanced error handling and validation (
dot-block-editor.component.ts:157-196)hasFieldErrorinput to receive external validation state from parent componentscharLimitErrorgetter to expose character limit validation errors to the templatehasErrorgetter combining external and internal error states for unified error stylingrequiredErrorgetter for displaying required field validation messagesupdateCharLimitValidity()method that validates character count againstcharLimitand setscharLimitExceededform control errorclearCharLimitError()method to properly remove char limit errors while preserving other validation errorscreate,update, and properonTouchedhandling onblureventsTemplate improvements (
dot-block-editor.component.html:26-54)editor-wrapper--errorclass applied when validation errors existStyling enhancements (
dot-block-editor.component.scss:48-122).editor-wrapper--errorclass with red outline for visual error indication.block-editor__footerwith flexbox layout for error messages and countersComprehensive test coverage (
dot-block-editor.component.spec.ts:442-672)hasFieldErrorinput behavior andhasErrorgetter combinationscharLimitErrorgetter with various error statesrequiredErrorwith touched/untouched control statesonBlockEditorChangetests for character limit validation edge cases (exceeds limit, within limit, at limit, no limit, preserving other errors)Edit Content Form Integration
Validator integration (
core-web/libs/edit-content/src/lib/components/dot-edit-content-form/dot-edit-content-form.component.ts:526-573)blockEditorRequiredValidator()for Story Block fields instead of genericValidators.requiredCustom validators (
core-web/libs/edit-content/src/lib/utils/validators.ts:1-82)blockEditorRequiredValidator()function that validates Story Block content has meaningful textvalidators.spec.ts) with 12 test cases covering empty content, whitespace-only, valid text, nested structures, and edge casesField wrapper enhancements (
core-web/libs/edit-content/src/lib/fields/shared/base-wrapper-field.ts)fieldHasErrorgetter to expose form control validation state to child componentsTemplate updates (
dot-edit-content-block-editor.component.html:16)hasFieldErrorbinding to block editor component for external error stateBackend (Java)
Story Block Validation Utilities
Enhanced validation logic (
dotCMS/src/main/java/com/dotcms/contenttype/util/StoryBlockUtil.java)validateCharLimit()method that parses Story Block JSON and counts plain text charactersDotContentletValidationExceptionwithCHAR_LIMIT_EXCEEDEDcode when limit exceededvalidateContent()method with proper null/empty checksComprehensive test coverage (
dotCMS/src/integration-test/java/com/dotcms/contenttype/test/StoryBlockUtilTest.java)Exception Handling Enhancements
Extended validation exception (
dotCMS/src/main/java/com/dotmarketing/business/DotContentletValidationException.java:61-88)CHAR_LIMIT_EXCEEDEDvalidation code with field name and character limit parametersSTORYBLOCK_INVALID_JSONcode for malformed Story Block contentNew exception utilities (
dotCMS/src/main/java/com/dotcms/exception/ExceptionUtil.java:1-14)getValidationException()helper method for creating validation exceptions with proper error codesAPI Integration
ESContentletAPIImpl (
dotCMS/src/main/java/com/dotcms/business/ESContentletAPIImpl.java)StoryBlockUtil.validateContent()for all Story Block fields with character limitsContentletAjax (
dotCMS/src/main/java/com/dotcms/rest/api/v1/portlets/contentlet/ajax/ContentletAjax.java)Language Properties
dotCMS/src/main/webapp/WEB-INF/messages/Language.properties)dot.edit.content.form.field.charLimitExceededmessage for frontend error displayTests
Frontend Tests
Block editor validation tests (
dot-block-editor.component.spec.ts)Custom validator tests (
validators.spec.ts)blockEditorRequiredValidator()covering empty content, whitespace, valid text, nested structuresBackend Tests
Story Block validation tests (
StoryBlockValidationTest.java)StoryBlockUtil tests (
StoryBlockUtilTest.java)Configuration & Documentation
TypeScript unit testing agent (
.cursor/agents/typescript-unit-testing.md)MCP server configuration (
core-web/.mcp.json,core-web/.gemini/settings.json)Documentation formatting (
core-web/CLAUDE.md,core-web/AGENTS.md)Technical Details
Character Limit Validation Flow
Frontend Real-time Validation:
updateevent,updateCharLimitValidity()compares count against configuredcharLimitcharLimitExceedederror on form control and marks as touchedBackend Server-side Validation:
StoryBlockUtil.validateContent()is calledDotContentletValidationExceptionwithCHAR_LIMIT_EXCEEDEDcode if limit exceededError Handling Architecture
hasErrorgetter combines external validation (hasFieldError) with internal char limit validationclearCharLimitError()properly removes char limit errors while preserving other validation errors (required, regex, etc.)ControlValueAccessorpattern withonTouched()called on blur, not on every changeKey Design Decisions
{"type":"doc","content":[]}) is technically a value, but not meaningful contentCHAR_LIMIT_EXCEEDED) instead of string messages for better localization and client-side handlingBreaking Changes
None
Testing
Related Issues
Closes #34304
Additional Notes
UtilMethods.isSet()for null checks,Loggerfor logging, and proper exception hierarchy@if,input(),data-testid) as per dotCMS frontend standardsThis PR fixes: #34304