Skip to content

Commit dffea35

Browse files
kart-ukasya
andauthored
refactor-replace-with-replaceAll (#2526)
* refactor-replace-with-replaceAll * Update global regex for replaceAll() --------- Co-authored-by: Kate <[email protected]>
1 parent 0083617 commit dffea35

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

frontend/__tests__/unit/components/AnchorTitle.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jest.mock('utils/slugify', () => ({
1111
default: jest.fn((str: string) =>
1212
str
1313
.toLowerCase()
14-
.replace(/[^a-z0-9]/g, '-')
15-
.replace(/-{2,10}/g, '-')
16-
.replace(/(^-{1,10}|-{1,10}$)/g, '')
14+
.replaceAll(/[^a-z0-9]/g, '-')
15+
.replaceAll(/-{2,10}/g, '-')
16+
.replaceAll(/(^-{1,10}|-{1,10}$)/g, '')
1717
),
1818
}))
1919

@@ -652,9 +652,9 @@ describe('AnchorTitle Component', () => {
652652
mockFn.mockImplementation((str: string) =>
653653
str
654654
.toLowerCase()
655-
.replace(/[^a-z0-9]/g, '-')
656-
.replace(/-{2,10}/g, '-')
657-
.replace(/(^-{1,10}|-{1,10}$)/g, '')
655+
.replaceAll(/[^a-z0-9]/g, '-')
656+
.replaceAll(/-{2,10}/g, '-')
657+
.replaceAll(/(^-{1,10}|-{1,10}$)/g, '')
658658
)
659659

660660
const mockScrollTo = jest.spyOn(globalThis, 'scrollTo').mockImplementation()

frontend/__tests__/unit/components/MarkdownWrapper.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jest.mock('markdown-it/index.mjs', () => {
1111
render: (content: string) => {
1212
// Very simple mock: replace **bold** and [link](url)
1313
return content
14-
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
15-
.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>')
14+
.replaceAll(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
15+
.replaceAll(/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>')
1616
},
1717
use: jest.fn().mockReturnThis(),
1818
}))

frontend/__tests__/unit/pages/UserDetails.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jest.mock('components/Badges', () => {
4141
showTooltip?: boolean
4242
}) => (
4343
<div
44-
data-testid={`badge-${name.toLowerCase().replace(/\s+/g, '-')}`}
44+
data-testid={`badge-${name.toLowerCase().replaceAll(/\s+/g, '-')}`}
4545
data-css-class={cssClass}
4646
data-show-tooltip={showTooltip}
4747
>

frontend/src/app/board/[year]/candidates/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const BoardCandidatesPage = () => {
189189

190190
const handleCardClick = () => {
191191
// Convert name to slug format.
192-
const nameSlug = candidate.memberName.toLowerCase().replace(/\s+/g, '_')
192+
const nameSlug = candidate.memberName.toLowerCase().replaceAll(/\s+/g, '_')
193193
const candidateUrl = `https://owasp.org/www-board-candidates/${year}/${nameSlug}.html`
194194
window.open(candidateUrl, '_blank', 'noopener,noreferrer')
195195
}
@@ -295,7 +295,7 @@ const BoardCandidatesPage = () => {
295295
}
296296
className="text-gray-700 dark:text-gray-300"
297297
>
298-
{candidate.member.bio.replace(/\n+/g, ' ').replace(/\s+/g, ' ').trim()}
298+
{candidate.member.bio.replaceAll(/\n+/g, ' ').replaceAll(/\s+/g, ' ').trim()}
299299
</div>
300300
)}
301301
</div>

frontend/src/components/Badges.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const normalizeCssClass = (cssClass: string | undefined) => {
1616
}
1717

1818
// Convert backend snake_case format to frontend camelCase format
19-
return cssClass.trim().replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
19+
return cssClass.trim().replaceAll(/_([a-z])/g, (_, letter) => letter.toUpperCase())
2020
}
2121

2222
const resolveIcon = (cssClass: string | undefined) => {

frontend/src/components/BreadCrumbs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function BreadCrumbs() {
4343

4444
{segments.map((segment, index) => {
4545
const href = homeRoute + segments.slice(0, index + 1).join(homeRoute)
46-
const label = upperFirst(segment).replace(/-/g, ' ')
46+
const label = upperFirst(segment).replaceAll('-', ' ')
4747
const isLast = index === segments.length - 1
4848

4949
return (

frontend/src/utils/slugify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default function slugify(text: string): string {
22
return text
33
.normalize('NFKD') // Normalize accented characters
4-
.replace(/[\u0300-\u036F]/g, '') // Remove diacritics
5-
.replace(/[^a-zA-Z0-9]+/g, '-') // Replace non-alphanumeric with hyphens
4+
.replaceAll(/[\u0300-\u036F]/g, '') // Remove diacritics
5+
.replaceAll(/[^a-zA-Z0-9]+/g, '-') // Replace non-alphanumeric with hyphens
66
.replace(/^[-]+/, '') // Trim leading hyphens
77
.replace(/[-]+$/, '') // Trim trailing hyphens
88
.toLowerCase()

0 commit comments

Comments
 (0)