mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Do not proxy image data uri (#421)
* do not proxy image data uri * rename data uri * rename data uri in test
This commit is contained in:
parent
2c9c2a2adf
commit
72a231c97e
2 changed files with 16 additions and 3 deletions
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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: <img src=\"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA" +
|
||||
"AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\"" +
|
||||
" alt=\"Red dot\" />");
|
||||
var expected_xhtml = "<div id=\"readability-page-1\" class=\"page\">My cat: <img src=\"data:image/png;base64," +
|
||||
" iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0" +
|
||||
"Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\"></div>";
|
||||
var content = new Readability(dom.window.document).parse().content;
|
||||
expect(content).eql(expected_xhtml);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue