mozilla / readability

A standalone version of the readability lib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error during parsing | ReferenceError: li_count is not defined

MMMartt opened this issue Β· comments

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @mozilla/readability@0.4.3 for the project I'm working on.

My code runs in a browser extension and throws an error when parsing a specific website, such as this. The code is not imported in the usual way (as in an extension), so I'm not sure why it doesn't throw an error normally. However, it's clear that these codes is not correct.

Here is the diff that solved my problem:

diff --git a/node_modules/@mozilla/readability/Readability.js b/node_modules/@mozilla/readability/Readability.js
index 35021e9..4c11d4a 100644
--- a/node_modules/@mozilla/readability/Readability.js
+++ b/node_modules/@mozilla/readability/Readability.js
@@ -2147,7 +2147,7 @@ Readability.prototype = {
               return haveToRemove;
             }
           }
-          li_count = node.getElementsByTagName("li").length;
+          var li_count = node.getElementsByTagName("li").length;
           // Only allow the list to remain if every li contains an image
           if (img == li_count) {
             return false;

This issue body was partially generated by patch-package.

commented

Ugh, yeah, not sure how that got there. We should fix it.

That said, assigning to an undeclared variable in vanilla JS should work fine (and clearly does in our automated test suite!). Not sure why it breaks in your environment, that would be interesting to know...

Had the same issue (in a CloudFlare worker environment), downgrading to 0.4.2 worked around it for now.

commented

This is now fixed in a new version which is up on NPM as 0.4.4. Thanks for the report!