Skip to content

Commit 1ca99f3

Browse files
committed
add prop sanitization in icon property
1 parent d42d77c commit 1ca99f3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/scripts/Icon.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ export default class Icon extends Component {
153153
className
154154
);
155155

156-
const useHtml = `${getAssetRoot()}/icons/${category}-sprite/svg/symbols.svg#${icon}`;
156+
// icon and category prop should not include chars other than alphanumerics, underscore, and hyphen
157+
icon = (icon || '').replace(/[^\w\-]/g, ''); // eslint-disable-line no-param-reassign
158+
category = (category || '').replace(/[^\w\-]/g, ''); // eslint-disable-line no-param-reassign
159+
160+
const iconUrl = `${getAssetRoot()}/icons/${category}-sprite/svg/symbols.svg#${icon}`;
157161
return (
158162
<svg
159163
className={ iconClassNames }
@@ -162,7 +166,7 @@ export default class Icon extends Component {
162166
style={ style }
163167
{...props}
164168
>
165-
<use xlinkHref={useHtml} />
169+
<use xlinkHref={iconUrl} />
166170
</svg>
167171
);
168172
}

0 commit comments

Comments
 (0)