[fix] Image support for SVG base64 data

The previous fix to support inline SVG data in utf-8 format broke images
that were rendering base64 SVGs.
This commit is contained in:
Nicolas Gallagher
2018-02-17 15:46:40 -08:00
parent 9fe089ca21
commit 31db333ba3
3 changed files with 20 additions and 13 deletions
+7 -7
View File
@@ -56,7 +56,7 @@ const resolveAssetDimensions = source => {
}
};
const svgDataUriPattern = /^data:image\/svg\+xml;/;
const svgDataUriPattern = /^(data:image\/svg\+xml;utf8,)(.*)/;
const resolveAssetSource = source => {
let uri;
if (typeof source === 'number') {
@@ -71,12 +71,12 @@ const resolveAssetSource = source => {
uri = source || '';
}
// SVG data may contain characters (e.g., #, ") that need to be escaped
if (svgDataUriPattern.test(uri)) {
const parts = uri.split('<svg');
const [prefix, ...svgFragment] = parts;
const svg = encodeURIComponent(`<svg${svgFragment.join('<svg')}`);
return `${prefix}${svg}`;
const match = uri.match(svgDataUriPattern);
// inline SVG markup may contain characters (e.g., #, ") that need to be escaped
if (match) {
const [, prefix, svg] = match;
const encodedSvg = encodeURIComponent(svg);
return `${prefix}${encodedSvg}`;
}
return uri;