fix: Escaped & when generating SVG.

This commit is contained in:
Adam Gaskins 2020-09-16 15:17:12 -04:00
parent 8263ca93c4
commit 66d2f39d80

View File

@ -48,8 +48,18 @@ class Icon {
*/
function attrsToString(attrs) {
return Object.keys(attrs)
.map(key => `${key}="${attrs[key]}"`)
.map(key => `${key}="${htmlEscape(attrs[key])}"`)
.join(' ');
}
/**
* Escapes unicode values in a string for XML compatibility (& => &)
* @param {string} str
* @returns {string}
*/
function htmlEscape(str) {
if (typeof str !== 'string') return str;
return str.replace(/&/g, '&');
}
export default Icon;