Merge pull request #95 from omnivore-app/fix/image-proxy-sizing

Handle non-number size attributes in images
This commit is contained in:
Jackson Harper 2022-02-22 00:31:29 +08:00 committed by GitHub
commit 68416fef12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -512,11 +512,18 @@ Readability.prototype = {
if (src) {
const absoluteSrc = this.toAbsoluteURI(src);
const attToNumber = (str) => {
if (!str) { return 0; }
const res = parseInt(str);
if (isNaN(res)) { return 0; }
if (String(res) !== str) { return 0; }
return res
}
const width = image.getAttribute('width') || image.style.width;
const height = image.getAttribute('height') || image.style.height;
const width = attToNumber(image.getAttribute('width') || image.style.width);
const height = attToNumber(image.getAttribute('height') || image.style.height);
const proxySrc = this.createImageProxyUrl(absoluteSrc, width || 0, height || 0);
const proxySrc = this.createImageProxyUrl(absoluteSrc, width, height);
image.setAttribute('src', proxySrc);
}
});