Skip to content

Commit 8c500ec

Browse files
authored
Merge pull request #204 from mashmatrix/fix-icon-property-sanitization
Add prop sanitization in icon/category property of Icon component
2 parents d42d77c + 138c839 commit 8c500ec

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/scripts/Icon.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,19 @@ export default class Icon extends Component {
144144
{
145145
'slds-icon': !/slds\-button__icon/.test(className),
146146
[`slds-icon--${size}`]: /^(x-small|small|medium|large)$/.test(size),
147-
[`slds-icon-text-${textColor}`]: /^(default|warning|error)$/.test(textColor) &&
148-
!iconColor,
147+
[`slds-icon-text-${textColor}`]: /^(default|warning|error)$/.test(textColor) && !iconColor,
149148
[`slds-icon-${iconColor}`]: !container && iconColor,
150149
'slds-m-left--x-small': align === 'right',
151150
'slds-m-right--x-small': align === 'left',
152151
},
153152
className
154153
);
155154

156-
const useHtml = `${getAssetRoot()}/icons/${category}-sprite/svg/symbols.svg#${icon}`;
155+
// icon and category prop should not include chars other than alphanumerics, underscore, and hyphen
156+
icon = (icon || '').replace(/[^\w\-]/g, ''); // eslint-disable-line no-param-reassign
157+
category = (category || '').replace(/[^\w\-]/g, ''); // eslint-disable-line no-param-reassign
158+
159+
const iconUrl = `${getAssetRoot()}/icons/${category}-sprite/svg/symbols.svg#${icon}`;
157160
return (
158161
<svg
159162
className={ iconClassNames }
@@ -162,7 +165,7 @@ export default class Icon extends Component {
162165
style={ style }
163166
{...props}
164167
>
165-
<use xlinkHref={useHtml} />
168+
<use xlinkHref={iconUrl} />
166169
</svg>
167170
);
168171
}

0 commit comments

Comments
 (0)