Skip to content

Commit

Permalink
Add hack to monkeypatch mozilla/readability#918
Browse files Browse the repository at this point in the history
  • Loading branch information
dbowring committed Oct 20, 2024
1 parent 1b7a1a0 commit af74a4a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/hacks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import validateNames from "jsdom/lib/jsdom/living/helpers/validate-names.js";

const applyJSDOMInvalidARgumentHack = () => {
// See: https://github.com/mozilla/readability/pull/918
const originalNameValidator = validateNames.name;
// @ts-expect-error
validateNames.name = (...args) => {
try {
originalNameValidator(...args);
} catch (ex) {
// @ts-expect-error
if (ex?.name !== "InvalidCharacterError") {
throw ex;
}
}
};
};

export const applyHacks = () => {
applyJSDOMInvalidARgumentHack();
};
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JSDOM } from "jsdom";
import { parseArgs } from "./cli";
import { applyHacks } from "./hacks";
import { readData, writeData } from "./io";
import { getReadability } from "./readability";
import { sanitizeHtml } from "./sanitize";
Expand All @@ -20,6 +21,7 @@ const getResult = async (data: string | Buffer, options: Options) => {
};

const main = async () => {
applyHacks();
const options = parseArgs();
const data = await readData(options.cli.path, options.cli.encoding);
const result = await getResult(data, options);
Expand Down

0 comments on commit af74a4a

Please sign in to comment.