Skip to content

Commit

Permalink
fix(strings): fix unintentional, IDE-induced Unicode encoding issue
Browse files Browse the repository at this point in the history
- use unicode Kelvin sign as `\u212a` to avoid/fix bug in `encodeEntitiesNum()`
  - potential culprits for this issue: VSCode or Prettier
- add tests
  • Loading branch information
postspectacular committed Mar 22, 2024
1 parent 918c3b8 commit a54a69b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/strings/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const ENTITIES: Record<string, string> = {
"™": "&trade;",
"℃": "&#8451;",
"℉": "&#8457;",
K: "&#8490;",
"\u212a": "&#8490;", // Kelvin
"◂": "&ltrif;",
"▸": "&rtrif;",
"▴": "&utrif;",
Expand Down
12 changes: 11 additions & 1 deletion packages/strings/test/escape.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect, test } from "bun:test";
import { escape, unescape } from "../src/index.js";
import {
escape,
escapeEntitiesNum,
unescape,
unescapeEntities,
} from "../src/index.js";

const SRC = "\ta\nb😎c£\\\x00";

Expand All @@ -10,3 +15,8 @@ test("escape", () => {
test("roundtrip", () => {
expect(unescape(escape(SRC))).toBe(SRC);
});

test("encodeEntitiesNum", () => {
expect(escapeEntitiesNum("KK℉Ü&")).toBe("K&#x212a;&#x2109;&#xdc;&amp;");
expect(unescapeEntities("K&#x212a;&#x2109;&#xdc;&amp;")).toBe("KK℉Ü&");
});

0 comments on commit a54a69b

Please sign in to comment.