From 977be42d1fb33781401001318813ab9fe4568647 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Mon, 24 Dec 2018 22:31:31 +0000 Subject: [PATCH] Fix link normalization for live HTMLCollections 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. --- Readability.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readability.js b/Readability.js index 21a64fae..22e7aece 100644 --- a/Readability.js +++ b/Readability.js @@ -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) { @@ -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) {