htmlparser2 icon indicating copy to clipboard operation
htmlparser2 copied to clipboard

Latest Entities (6.0.0) breaks latest htmlparser2

Open Chinoman10 opened this issue 10 months ago • 2 comments

[email protected] breaks htmlparser2.

version 6.0.0 is in the latest package.json of htmlparser2

htmlparser2 is expecting an export 'fromCodePoint' which isn't there anymore (after changing some imports in Tokenizer.js to fix yet another issue ⚠ ). Changes done to Tokenizer.js:

  • Original
import { EntityDecoder, DecodingMode, htmlDecodeTree, xmlDecodeTree, } from "entities/lib/decode.js";
  • Change:
import { EntityDecoder, DecodingMode, decode, } from "entities";
const xmlDecodeTree = (str) => decode(str);
const htmlDecodeTree = (str) => decode(str);

Had to do a similar thing to Parser.js...

After changing entities's index to export fromCodePoint, everything works again.

I'm not sure if this is an entities issue or an htmlparser2's issue, but since htmlparser2 is using [email protected], I assume that at least should be changed, either point to an older version, or patch entities to 6.0.1 and point to that newer (fixed) version instead.

Thanks for looking into this @fb55 .

Chinoman10 avatar Mar 14 '25 11:03 Chinoman10

I guess I could've also changed line 130:

  • Original this.entityDecoder = new EntityDecoder(xmlMode ? xmlDecodeTree : htmlDecodeTree, (cp, consumed) => this.emitCodePoint(cp, consumed));
  • Changed this.entityDecoder = new EntityDecoder(decode, (cp, consumed) => this.emitCodePoint(cp, consumed));

Easier than redefining xmlDecodeTree and htmlDecodeTree which both do the same thing...

Chinoman10 avatar Mar 14 '25 11:03 Chinoman10

Here are a couple patch files I added to my repo in order to get this working:

[email protected]

diff --git a/lib/esm/Parser.js b/lib/esm/Parser.js
index 68cc0ed4c6a421c4cd64e28a7e9538e6a1b974c8..3f3601772727cfc906216380460f57d15611db8a 100644
--- a/lib/esm/Parser.js
+++ b/lib/esm/Parser.js
@@ -1,5 +1,5 @@
 import Tokenizer, { QuoteType } from "./Tokenizer.js";
-import { fromCodePoint } from "entities/lib/decode.js";
+import { fromCodePoint } from "entities";
 const formTags = new Set([
     "input",
     "option",
diff --git a/lib/esm/Tokenizer.js b/lib/esm/Tokenizer.js
index a97456b05090e2ff63c6dc5410f6ab2b86f583ef..ddcce2f17a7897d37b2a737bb9dc378c70efcbbf 100644
--- a/lib/esm/Tokenizer.js
+++ b/lib/esm/Tokenizer.js
@@ -1,4 +1,4 @@
-import { htmlDecodeTree, xmlDecodeTree, BinTrieFlags, determineBranch, replaceCodePoint, } from "entities/lib/decode.js";
+import { htmlDecodeTree, xmlDecodeTree, BinTrieFlags, determineBranch, replaceCodePoint, } from "entities";
 var CharCodes;
 (function (CharCodes) {
     CharCodes[CharCodes["Tab"] = 9] = "Tab";

[email protected]

diff --git a/lib/esm/index.js b/lib/esm/index.js
index acc6dbe957317882cac35eda50c21caecf0d83ac..bf4149590b102fb9b33addfb9a40123da94832ce 100644
--- a/lib/esm/index.js
+++ b/lib/esm/index.js
@@ -93,7 +93,7 @@ export { encodeXML, escape, escapeUTF8, escapeAttribute, escapeText, } from "./e
 export { encodeHTML, encodeNonAsciiHTML, 
 // Legacy aliases (deprecated)
 encodeHTML as encodeHTML4, encodeHTML as encodeHTML5, } from "./encode.js";
-export { EntityDecoder, DecodingMode, decodeXML, decodeHTML, decodeHTMLStrict, decodeHTMLAttribute, 
+export { EntityDecoder, DecodingMode, decodeXML, decodeHTML, decodeHTMLStrict, decodeHTMLAttribute, fromCodePoint, htmlDecodeTree, xmlDecodeTree, BinTrieFlags, determineBranch, replaceCodePoint,
 // Legacy aliases (deprecated)
 decodeHTML as decodeHTML4, decodeHTML as decodeHTML5, decodeHTMLStrict as decodeHTML4Strict, decodeHTMLStrict as decodeHTML5Strict, decodeXML as decodeXMLStrict, } from "./decode.js";
 //# sourceMappingURL=index.js.map

seanadkinson avatar Oct 10 '25 23:10 seanadkinson