Skip to content

Commit

Permalink
fix: don't use alt attributes as image sources for lazily-loaded imag…
Browse files Browse the repository at this point in the history
…es (mozilla#689)
  • Loading branch information
shfshanyue authored Apr 15, 2021
1 parent f3d3cf8 commit e197236
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ Readability.prototype = {

for (var j = 0; j < elem.attributes.length; j++) {
attr = elem.attributes[j];
if (attr.name === "src" || attr.name === "srcset") {
if (attr.name === "src" || attr.name === "srcset" || attr.name === "alt") {
continue;
}
var copyTo = null;
Expand Down
7 changes: 7 additions & 0 deletions test/test-pages/lazy-image-3/expected-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Lazy Load with Alt includes jpg/png/webp extensions",
"byline": null,
"dir": null,
"siteName": null,
"readerable": false
}
8 changes: 8 additions & 0 deletions test/test-pages/lazy-image-3/expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="readability-page-1" class="page">
<article>
<h2>Test Case 1</h2>
<img data-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0579d17015b145a88dd93992c6447d7d~tplv-k3u1fbpfcp-watermark.jpg" alt="performance.jpg" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0579d17015b145a88dd93992c6447d7d~tplv-k3u1fbpfcp-watermark.jpg" />
<h2>Test Case 2</h2>
<img data-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0579d17015b145a88dd93992c6447d7d~tplv-k3u1fbpfcp-watermark.png" alt="performance.jpg" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0579d17015b145a88dd93992c6447d7d~tplv-k3u1fbpfcp-watermark.png" />
</article>
</div>
21 changes: 21 additions & 0 deletions test/test-pages/lazy-image-3/source.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Lazy Load with Alt includes jpg/png/webp extensions</title>
</head>
<body>
<article class="markdown-body">
<h2>Test Case 1</h2>
<img class="lazyload inited loaded"
data-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0579d17015b145a88dd93992c6447d7d~tplv-k3u1fbpfcp-watermark.jpg"
alt="performance.jpg"
/>
<h2>Test Case 2</h2>
<img class="lazyload inited loaded"
data-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0579d17015b145a88dd93992c6447d7d~tplv-k3u1fbpfcp-watermark.png"
alt="performance.jpg"
/>
</article>
</body>
</html>

0 comments on commit e197236

Please sign in to comment.