Skip to content

Commit

Permalink
Replace he with entities
Browse files Browse the repository at this point in the history
  • Loading branch information
perry-mitchell committed Apr 22, 2024
1 parent 1fe3271 commit db57262
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
24 changes: 21 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"sync"
],
"engines": {
"node": ">=14"
"node": ">=16"
},
"lint-staged": {
"{source,test}/**/*.{js,ts}": [
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions source/tools/encode.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions test/node/tools/encode.spec.ts
Original file line number Diff line number Diff line change
@@ -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 & ÿ ü '");
});
});
5 changes: 5 additions & 0 deletions util/entities.stub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function decodeHTML(..._: any): string {
return "";
}

export { decodeHTML };
1 change: 0 additions & 1 deletion util/he.stub.ts

This file was deleted.

2 changes: 1 addition & 1 deletion webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db57262

Please sign in to comment.