From 4f96abfb7b4eb9f2f5b4698084357e9b598b40b2 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Thu, 17 Aug 2017 23:32:03 +0800 Subject: [PATCH] Handle inline svg correctly with foreignObject --- src/ImageLoader.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ImageLoader.js b/src/ImageLoader.js index d6cdc21..371d35e 100644 --- a/src/ImageLoader.js +++ b/src/ImageLoader.js @@ -38,7 +38,7 @@ export default class ImageLoader { return this.addImage(src, src); } } else { - if (this.options.allowTaint === true || isInlineImage(src) || this.isSameOrigin(src)) { + if (this.options.allowTaint === true || isInlineBase64Image(src) || this.isSameOrigin(src)) { return this.addImage(src, src); } else if (typeof this.options.proxy === 'string' && !this.isSameOrigin(src)) { // TODO proxy @@ -121,7 +121,7 @@ export default class ImageLoader { }); this.cache[key] = - isInlineImage(src) && !isSVG(src) + isInlineBase64Image(src) && !isSVG(src) ? // $FlowFixMe FEATURES.SUPPORT_BASE64_DRAWING(src).then(imageLoadHandler) : imageLoadHandler(true); @@ -176,8 +176,10 @@ export class ImageStore { const INLINE_SVG = /^data:image\/svg\+xml/i; const INLINE_BASE64 = /^data:image\/.*;base64,/i; +const INLINE_IMG = /^data:image\/.*/i; -const isInlineImage = (src: string): boolean => INLINE_BASE64.test(src); +const isInlineImage = (src: string): boolean => INLINE_IMG.test(src); +const isInlineBase64Image = (src: string): boolean => INLINE_BASE64.test(src); const isSVG = (src: string): boolean => src.substr(-3).toLowerCase() === 'svg' || INLINE_SVG.test(src);