-
Notifications
You must be signed in to change notification settings - Fork 13.1k
fix: Prevent whitespace-only names in Create Discussion #38435
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
base: develop
Are you sure you want to change the base?
fix: Prevent whitespace-only names in Create Discussion #38435
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
WalkthroughAdded trimmed-value validation to the CreateDiscussion name field to reject whitespace-only names; changed a placeholder URL in UserAvatarEditor to a hardcoded example; wrapped GenericMenuItem icon rendering in a Box for layout control. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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.
No issues found across 3 files
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx`:
- Around line 133-151: The parentRoom Controller currently has two render props
and the trim validate rule is applied to parentRoom instead of the name field;
fix this by removing the duplicate render prop from the Controller that uses
DefaultParentRoomField (ensure that Controller has name='parentRoom' and only
renders <DefaultParentRoomField defaultParentRoom={defaultParentRoom}
id={parentRoomId} />), and move the rules including validate: (value) =>
value.trim().length > 0 || t('Required_field', { field: t('Name') }) to the
Controller that renders the <TextInput id={discussionNameId} ... /> so the
Controller with name='name' enforces both required and trim validation (keep
aria and error props like aria-invalid={Boolean(errors.name)}).
🧹 Nitpick comments (1)
packages/ui-client/src/components/GenericMenu/GenericMenuItem.tsx (1)
1-26: Remove inline explanatory comments in implementation.As per coding guidelines, Avoid code comments in the implementation.♻️ Proposed cleanup
-import { Box, MenuItemColumn, MenuItemContent, MenuItemIcon, MenuItemInput } from '@rocket.chat/fuselage'; // 1. Added Box import +import { Box, MenuItemColumn, MenuItemContent, MenuItemIcon, MenuItemInput } from '@rocket.chat/fuselage'; - {/* 2. Wrap the icon in a flexbox container */} {icon && ( <Box display='flex' alignItems='center' justifyContent='center' width='x20'>
This PR introduces a validation check to the "Create Discussion" modal to prevent the creation of discussions with names consisting solely of whitespace (spaces or tabs).
Previously, the required rule only checked for empty strings, allowing users to bypass validation with spaces, which resulted in unnamed and unidentifiable rooms in the sidebar. I have added a custom validate rule using .trim() to ensure the name contains at least one non-whitespace character before submission.
Issue(s)
Closes #38434
Steps to test or reproduce
Click the + icon in the sidebar and select Create Discussion.
Select a Parent channel or team.
In the Name field, enter only spaces (e.g., " ").
Observe that the Create button now triggers a validation error ("The field Name is required") instead of successfully creating an unnamed discussion.
Further comments
I used the validate function within the Controller component to leverage the existing react-hook-form logic and the project's translation strings (t('Required_field', ...)), ensuring a consistent UI and localized error messages.
Summary by CodeRabbit
Bug Fixes
UI Improvements
✏️ Tip: You can customize this high-level summary in your review settings.