mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-07 04:05:01 +00:00
[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:
+7
-7
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user