diff --git a/packages/readabilityjs/Readability.js b/packages/readabilityjs/Readability.js index 36d09102c..c68b5de88 100644 --- a/packages/readabilityjs/Readability.js +++ b/packages/readabilityjs/Readability.js @@ -504,15 +504,17 @@ Readability.prototype = { }); }, - /** Creates imageproxy links for all article images */ + /** Creates imageproxy links for all article images with href source */ _createImageProxyLinks: function (articleContent) { if (this.createImageProxyUrl !== undefined) { - // replace all image src's + // replace all images' href source const images = articleContent.getElementsByTagName('img'); Array.from(images).forEach(image => { const src = image.getAttribute("src"); + const dataUriRegex = /^data:image\/(?:png|jpe?g|gif);base64,/; - if (src) { + // do not proxy data uri + if (src && !dataUriRegex.test(src)) { const absoluteSrc = this.toAbsoluteURI(src); const attToNumber = (str) => { if (!str) { return 0; } diff --git a/packages/readabilityjs/test/test-readability.js b/packages/readabilityjs/test/test-readability.js index 7c80abfe6..44c00e44b 100644 --- a/packages/readabilityjs/test/test-readability.js +++ b/packages/readabilityjs/test/test-readability.js @@ -270,6 +270,17 @@ describe("Readability API", function() { }).parse().content; expect(content).eql(expected_xhtml); }); + + it("should not proxy image with data uri", function() { + var dom = new JSDOM("My cat: \"Red"); + var expected_xhtml = "
My cat: \"Red
"; + var content = new Readability(dom.window.document).parse().content; + expect(content).eql(expected_xhtml); + }); }); });