From db57262cd06d151d719123a2d61eef66961f7f74 Mon Sep 17 00:00:00 2001 From: Perry Mitchell Date: Mon, 22 Apr 2024 20:22:25 +0300 Subject: [PATCH] Replace he with entities --- package-lock.json | 24 +++++++++++++++++++++--- package.json | 4 ++-- source/tools/encode.ts | 4 ++-- test/node/tools/encode.spec.ts | 12 ++++++++++++ util/entities.stub.ts | 5 +++++ util/he.stub.ts | 1 - webpack.config.cjs | 2 +- 7 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 test/node/tools/encode.spec.ts create mode 100644 util/entities.stub.ts delete mode 100644 util/he.stub.ts diff --git a/package-lock.json b/package-lock.json index 4bff4da6..06275029 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,8 @@ "@buttercup/fetch": "^0.2.1", "base-64": "^1.0.0", "byte-length": "^1.0.2", + "entities": "^4.5.0", "fast-xml-parser": "^4.2.4", - "he": "^1.2.0", "hot-patcher": "^2.0.0", "layerr": "^2.0.1", "md5": "^2.3.0", @@ -72,7 +72,7 @@ "webpack-merge": "^5.10.0" }, "engines": { - "node": ">=14" + "node": ">=16" } }, "node_modules/@ampproject/remapping": { @@ -4006,6 +4006,17 @@ "integrity": "sha1-6WQhkyWiHQX0RGai9obtbOX13R0=", "dev": true }, + "node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/envinfo": { "version": "7.8.1", "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.8.1.tgz", @@ -4826,6 +4837,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true, "bin": { "he": "bin/he" } @@ -12379,6 +12391,11 @@ "integrity": "sha1-6WQhkyWiHQX0RGai9obtbOX13R0=", "dev": true }, + "entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==" + }, "envinfo": { "version": "7.8.1", "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.8.1.tgz", @@ -12950,7 +12967,8 @@ "he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", - "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true }, "hosted-git-info": { "version": "2.8.9", diff --git a/package.json b/package.json index c3b09b03..58ac987a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "sync" ], "engines": { - "node": ">=14" + "node": ">=16" }, "lint-staged": { "{source,test}/**/*.{js,ts}": [ @@ -69,8 +69,8 @@ "@buttercup/fetch": "^0.2.1", "base-64": "^1.0.0", "byte-length": "^1.0.2", + "entities": "^4.5.0", "fast-xml-parser": "^4.2.4", - "he": "^1.2.0", "hot-patcher": "^2.0.0", "layerr": "^2.0.1", "md5": "^2.3.0", diff --git a/source/tools/encode.ts b/source/tools/encode.ts index 72e212ff..23ca699e 100644 --- a/source/tools/encode.ts +++ b/source/tools/encode.ts @@ -1,5 +1,5 @@ import base64 from "base-64"; -import he from "he"; +import { decodeHTML } from "entities"; import { isWeb } from "../compat/env.js"; export function decodeHTMLEntities(text: string): string { @@ -8,7 +8,7 @@ export function decodeHTMLEntities(text: string): string { txt.innerHTML = text; return txt.value; } - return he.decode(text); + return decodeHTML(text); } export function fromBase64(text: string): string { diff --git a/test/node/tools/encode.spec.ts b/test/node/tools/encode.spec.ts new file mode 100644 index 00000000..ae055a2a --- /dev/null +++ b/test/node/tools/encode.spec.ts @@ -0,0 +1,12 @@ +import { expect } from "chai"; +import { decodeHTMLEntities } from "../../../source/tools/encode.js"; + +describe("decodeHTMLEntities", function () { + it("decodes XML entities correctly", function () { + expect(decodeHTMLEntities("asdf & ÿ ü '")).to.equal("asdf & ÿ ü '"); + }); + + it("decodes HTML entities correctly", function () { + expect(decodeHTMLEntities("asdf & ÿ ü '")).to.equal("asdf & ÿ ü '"); + }); +}); diff --git a/util/entities.stub.ts b/util/entities.stub.ts new file mode 100644 index 00000000..8bd9287d --- /dev/null +++ b/util/entities.stub.ts @@ -0,0 +1,5 @@ +function decodeHTML(..._: any): string { + return ""; +} + +export { decodeHTML }; diff --git a/util/he.stub.ts b/util/he.stub.ts deleted file mode 100644 index ff8b4c56..00000000 --- a/util/he.stub.ts +++ /dev/null @@ -1 +0,0 @@ -export default {}; diff --git a/webpack.config.cjs b/webpack.config.cjs index d23d0745..bbc1f4de 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -88,7 +88,7 @@ module.exports = [ resolve: { alias: { - he: path.resolve(__dirname, "./util/he.stub.ts") + entities: path.resolve(__dirname, "./util/entities.stub.ts") }, plugins: [ // Handle .ts => .js resolution