Skip to content

Commit 2333080

Browse files
authored
Fix undefined li count (#792)
* Fix undefined li_count assignment * Fix eslint environments and enable no-undef linting * Add changelog bits.
1 parent 2aa4a64 commit 2333080

11 files changed

+35
-14
lines changed

.eslintrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
/* eslint-env node */
12
"use strict";
23

34
module.exports = {
45
"parserOptions": {
56
"ecmaVersion": 6
67
},
8+
"env": {
9+
"es6": true,
10+
"shared-node-browser": true,
11+
},
712
"rules": {
813
// Braces only needed for multi-line arrow function blocks
914
// "arrow-body-style": [2, "as-needed"],
@@ -146,7 +151,7 @@ module.exports = {
146151
"no-trailing-spaces": 2,
147152

148153
// No using undeclared variables
149-
// "no-undef": 2,
154+
"no-undef": 2,
150155

151156
// Error on newline where a semicolon is needed
152157
"no-unexpected-multiline": 2,

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ may change this output. Patch version increments will only do so in ways that ar
1111
strict improvements (e.g. from empty strings or exceptions to something more
1212
reasonable).
1313

14+
## [Unreleased]
15+
- Fixed [undefined `li_count` variable breaking use of readability in Cloudflare workers](https://github.com/mozilla/readability/issues/791)
16+
1417
## [0.4.3] - 2023-03-22
1518

1619
- Fixed [`aria-modal` cookie dialogs interfering with readability](https://github.com/mozilla/readability/pull/746)

JSDOMParser.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*eslint-env es6:false*/
21
/* This Source Code Form is subject to the terms of the Mozilla Public
32
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
43
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -874,10 +873,11 @@
874873

875874
JSDOMParser.prototype = {
876875
error: function(m) {
877-
if (typeof dump !== "undefined") {
878-
dump("JSDOMParser error: " + m + "\n");
879-
} else if (typeof console !== "undefined") {
876+
if (typeof console !== "undefined") {
880877
console.log("JSDOMParser error: " + m + "\n");
878+
} else if (typeof dump !== "undefined") {
879+
/* global dump */
880+
dump("JSDOMParser error: " + m + "\n");
881881
}
882882
this.errorState += m + "\n";
883883
},
@@ -1192,5 +1192,6 @@
11921192
})(this);
11931193

11941194
if (typeof module === "object") {
1195+
/* global module */
11951196
module.exports = this.JSDOMParser;
11961197
}

Readability-readerable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-env es6:false */
21
/*
32
* Copyright (c) 2010 Arc90 Inc
43
*
@@ -104,5 +103,6 @@ function isProbablyReaderable(doc, options = {}) {
104103
}
105104

106105
if (typeof module === "object") {
106+
/* global module */
107107
module.exports = isProbablyReaderable;
108108
}

Readability.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*eslint-env es6:false*/
21
/*
32
* Copyright (c) 2010 Arc90 Inc
43
*
@@ -74,12 +73,7 @@ function Readability(doc, options) {
7473
return `<${node.localName} ${attrPairs}>`;
7574
};
7675
this.log = function () {
77-
if (typeof dump !== "undefined") {
78-
var msg = Array.prototype.map.call(arguments, function(x) {
79-
return (x && x.nodeName) ? logNode(x) : x;
80-
}).join(" ");
81-
dump("Reader: (Readability) " + msg + "\n");
82-
} else if (typeof console !== "undefined") {
76+
if (typeof console !== "undefined") {
8377
let args = Array.from(arguments, arg => {
8478
if (arg && arg.nodeType == this.ELEMENT_NODE) {
8579
return logNode(arg);
@@ -88,6 +82,12 @@ function Readability(doc, options) {
8882
});
8983
args.unshift("Reader: (Readability)");
9084
console.log.apply(console, args);
85+
} else if (typeof dump !== "undefined") {
86+
/* global dump */
87+
var msg = Array.prototype.map.call(arguments, function(x) {
88+
return (x && x.nodeName) ? logNode(x) : x;
89+
}).join(" ");
90+
dump("Reader: (Readability) " + msg + "\n");
9191
}
9292
};
9393
} else {
@@ -2147,7 +2147,7 @@ Readability.prototype = {
21472147
return haveToRemove;
21482148
}
21492149
}
2150-
li_count = node.getElementsByTagName("li").length;
2150+
let li_count = node.getElementsByTagName("li").length;
21512151
// Only allow the list to remain if every li contains an image
21522152
if (img == li_count) {
21532153
return false;
@@ -2296,5 +2296,6 @@ Readability.prototype = {
22962296
};
22972297

22982298
if (typeof module === "object") {
2299+
/* global module */
22992300
module.exports = Readability;
23002301
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-env node */
12
var Readability = require("./Readability");
23
var isProbablyReaderable = require("./Readability-readerable");
34

test/generate-testcase.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-env node, mocha */
2+
13
var debug = false;
24

35
var path = require("path");

test/test-isProbablyReaderable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-env node, mocha */
2+
13
var JSDOM = require("jsdom").JSDOM;
24
var chai = require("chai");
35
chai.config.includeStack = true;

test/test-jsdomparser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-env node, mocha */
2+
13
var chai = require("chai");
24
chai.config.includeStack = true;
35
var expect = chai.expect;

test/test-readability.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-env node, mocha */
2+
13
var JSDOM = require("jsdom").JSDOM;
24
var chai = require("chai");
35
var sinon = require("sinon");

0 commit comments

Comments
 (0)