Skip to content

Commit b571de1

Browse files
Merge pull request #1594 from topcoder-platform/PM-226
PM-226 Fix React bad practice: dangerouslySetInnerhtml
2 parents 5ec54e9 + e12f3ba commit b571de1

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

src/components/ChallengeEditor/ChallengeView/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import PropTypes from 'prop-types'
44
import cn from 'classnames'
55
import { withRouter } from 'react-router-dom'
66
import styles from './ChallengeView.module.scss'
7-
import xss from 'xss'
87
import Track from '../../Track'
98
import NDAField from '../NDAField'
109
import UseSchedulingAPIField from '../UseSchedulingAPIField'
@@ -114,10 +113,7 @@ const ChallengeView = ({
114113
<div className={cn(styles.row, styles.topRow)}>
115114
<div className={styles.col}>
116115
<span>
117-
<span className={styles.fieldTitle}>Project:</span>
118-
<span dangerouslySetInnerHTML={{
119-
__html: xss(projectDetail ? projectDetail.name : '')
120-
}} />
116+
<span className={styles.fieldTitle}>Project: {projectDetail ? projectDetail.name : ''}</span>
121117
</span>
122118
</div>
123119
{selectedMilestone &&

src/components/ChallengeEditor/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import moment from 'moment-timezone'
88
import { pick } from 'lodash/fp'
99
import { withRouter } from 'react-router-dom'
1010
import { toastr } from 'react-redux-toastr'
11-
import xss from 'xss'
12-
1311
import {
1412
VALIDATION_VALUE_TYPE,
1513
PRIZE_SETS_TYPE,
@@ -1704,10 +1702,7 @@ class ChallengeEditor extends Component {
17041702
<div className={cn(styles.row, styles.topRow)}>
17051703
<div className={styles.col}>
17061704
<span>
1707-
<span className={styles.fieldTitle}>Project:</span>
1708-
<span dangerouslySetInnerHTML={{
1709-
__html: xss(projectDetail ? projectDetail.name : '')
1710-
}} />
1705+
<span className={styles.fieldTitle}>Project: {projectDetail ? projectDetail.name : ''}</span>
17111706
</span>
17121707
</div>
17131708
<div className={styles.col}>

src/components/ChallengesComponent/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { CONNECT_APP_URL, PROJECT_ROLES } from '../../config/constants'
1010
import { PrimaryButton } from '../Buttons'
1111
import ChallengeList from './ChallengeList'
1212
import styles from './ChallengesComponent.module.scss'
13-
import xss from 'xss'
1413
import { checkReadOnlyRoles } from '../../util/tc'
1514

1615
const ChallengesComponent = ({
@@ -61,12 +60,9 @@ const ChallengesComponent = ({
6160
<Helmet title={activeProject ? activeProject.name : ''} />
6261
{!dashboard && <div className={styles.titleContainer}>
6362
<div className={styles.titleLinks}>
64-
<div
65-
className={styles.title}
66-
dangerouslySetInnerHTML={{
67-
__html: xss(activeProject ? activeProject.name : '')
68-
}}
69-
/>
63+
<div className={styles.title}>
64+
{activeProject ? activeProject.name : ''}
65+
</div>
7066
{activeProject && activeProject.id && (
7167
<span>
7268
(

src/components/ProjectCard/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react'
22
import PT from 'prop-types'
33
import { Link } from 'react-router-dom'
44
import cn from 'classnames'
5-
import xss from 'xss'
65

76
import styles from './ProjectCard.module.scss'
87

@@ -14,7 +13,7 @@ const ProjectCard = ({ projectName, projectId, selected, setActiveProject }) =>
1413
className={cn(styles.projectName, { [styles.selected]: selected })}
1514
onClick={() => setActiveProject(parseInt(projectId))}
1615
>
17-
<div className={styles.name} dangerouslySetInnerHTML={{ __html: xss(projectName) }} />
16+
<div className={styles.name}>{projectName}</div>
1817
</Link>
1918
</div>
2019
)

0 commit comments

Comments
 (0)