Skip to content

Commit

Permalink
Fix link normalization for live HTMLCollections
Browse files Browse the repository at this point in the history
Newer versions of JSDOM implement getElementsByTagName correctly.
This means it returns a live node list. When calling
`Element.replaceChild` for links inside the loop over that
collection, elements disappear from the list, meaning we miss
every other item. Without this fix, the `clean-links` testcase
breaks.
  • Loading branch information
gijsk committed Dec 29, 2018
1 parent e8bb7f7 commit 977be42
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ Readability.prototype = {
return uri;
}

var links = articleContent.getElementsByTagName("a");
var links = this._getAllNodesWithTag(articleContent, ["a"]);
this._forEachNode(links, function(link) {
var href = link.getAttribute("href");
if (href) {
Expand All @@ -336,7 +336,7 @@ Readability.prototype = {
}
});

var imgs = articleContent.getElementsByTagName("img");
var imgs = this._getAllNodesWithTag(articleContent, ["img"]);
this._forEachNode(imgs, function(img) {
var src = img.getAttribute("src");
if (src) {
Expand Down

0 comments on commit 977be42

Please sign in to comment.