Handle non-number size attributes in images

The previous code assumed we would always have number size values
for width and height, but attributes like 100% are valid. In
cases where we don't have a numeric value we can just fallback
and let the item be sized by the reader CSS.
This commit is contained in:
Jackson Harper
2022-02-18 14:18:33 -08:00
parent dbd698f7f2
commit 612822f5a3

View File

@ -512,11 +512,17 @@ Readability.prototype = {
if (src) {
const absoluteSrc = this.toAbsoluteURI(src);
const parseNumber = (str) => {
if (!str) { return 0; }
const res = parseNumber(str);
if (isNaN(res)) { return 0; }
return res
}
const width = image.getAttribute('width') || image.style.width;
const height = image.getAttribute('height') || image.style.height;
const width = parseNumber(image.getAttribute('width') || image.style.width);
const height = parseNumber(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);
}
});