-
-
Notifications
You must be signed in to change notification settings - Fork 2
TT-6957 Enhance OrgHead component to sanitize organization names in display #161
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -549,4 +549,51 @@ describe('OrgHead', () => { | |||||
| // Should NOT display the organization name | ||||||
| cy.contains(orgName).should('not.exist'); | ||||||
| }); | ||||||
|
|
||||||
| it('should not display organization name that starts with > or ends with <', () => { | ||||||
| const orgId = 'test-org-id'; | ||||||
| // Test with name that starts with > | ||||||
| const orgNameWithPrefix = '>Test Organization'; | ||||||
| const orgDataWithPrefix = createMockOrganization(orgId, orgNameWithPrefix); | ||||||
|
|
||||||
| mountOrgHead(createInitialState(), ['/team'], orgId, orgDataWithPrefix); | ||||||
|
|
||||||
| // The displayed name should not start with > | ||||||
| cy.get('h6, [variant="h6"]') | ||||||
| .should('be.visible') | ||||||
| .then(($el) => { | ||||||
| const displayedText = $el.text(); | ||||||
| expect(displayedText.startsWith('>')).to.be.false; | ||||||
| expect(displayedText).to.equal('Test Organization'); | ||||||
| }); | ||||||
|
|
||||||
| // Test with name that ends with < | ||||||
| const orgNameWithSuffix = 'Test Organization<'; | ||||||
| const orgDataWithSuffix = createMockOrganization(orgId, orgNameWithSuffix); | ||||||
|
|
||||||
| mountOrgHead(createInitialState(), ['/team'], orgId, orgDataWithSuffix); | ||||||
|
|
||||||
| // The displayed name should not end with < | ||||||
| cy.get('h6, [variant="h6"]') | ||||||
| .should('be.visible') | ||||||
| .then(($el) => { | ||||||
| const displayedText = $el.text(); | ||||||
| expect(displayedText.endsWith('<')).to.be.false; | ||||||
| expect(displayedText).to.equal('Test Organization'); | ||||||
| }); | ||||||
|
||||||
| }); | |
| }); |
Outdated
Copilot
AI
Dec 13, 2025
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.
The test cases don't cover several edge cases for the cleanOrgName function: (1) names with multiple leading '>' characters (e.g., '>>Test'), (2) names with multiple trailing '<' characters (e.g., 'Test<<'), (3) names where '>' or '<' appear in the middle (e.g., 'Test>Organization'), (4) names that are just '>' or '<' alone, (5) names with mixed characters like '>><Test<'. Adding these test cases would ensure the sanitization function behaves as expected in all scenarios.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -85,6 +85,18 @@ export const OrgHead = () => { | |||||||||||||||||||
| setOpenMember(true); | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const cleanOrgName = (orgRec: OrganizationD | undefined) => { | ||||||||||||||||||||
| let name = orgRec?.attributes.name; | ||||||||||||||||||||
| if (!name) return ''; | ||||||||||||||||||||
| if (name.startsWith('>')) { | ||||||||||||||||||||
| name = name.slice(1); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (name.endsWith('<')) { | ||||||||||||||||||||
| name = name.slice(0, -1); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return name; | ||||||||||||||||||||
|
Comment on lines
+91
to
+97
|
||||||||||||||||||||
| if (name.startsWith('>')) { | |
| name = name.slice(1); | |
| } | |
| if (name.endsWith('<')) { | |
| name = name.slice(0, -1); | |
| } | |
| return name; | |
| // Remove all leading '>' and all trailing '<' characters, but leave any in the middle | |
| return name.replace(/^>+/, '').replace(/<+$/, ''); |
Uh oh!
There was an error while loading. Please reload this page.