diff --git a/src/hacks.ts b/src/hacks.ts new file mode 100644 index 0000000..9ca742d --- /dev/null +++ b/src/hacks.ts @@ -0,0 +1,22 @@ +// @ts-ignore +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(); +}; diff --git a/src/index.ts b/src/index.ts index 7b88b95..a452d8f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; @@ -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);