Skip to content

The job search that runs on your machine. AI job application framework built on Claude Code: evaluate postings, tailor CVs, write cover letters, prep interviews. Fork it and own it.

fix(linkedin-search): decode hex HTML entities in CLI output (#55)

Yiğit ERDOĞANb27a3b5e810d
diff --git a/.agents/skills/linkedin-search/cli/src/helpers.ts b/.agents/skills/linkedin-search/cli/src/helpers.ts
index 56308b3b..19e02003 100644
--- a/.agents/skills/linkedin-search/cli/src/helpers.ts
+++ b/.agents/skills/linkedin-search/cli/src/helpers.ts
@@ -67,6 +67,15 @@ export interface JobDetail extends JobCard {
applyUrl: string | null
}
+/**
+ * Convert a Unicode code point to a string. Uses `fromCodePoint` (not
+ * `fromCharCode`) so supplementary-plane code points (e.g. emoji, U+1F600)
+ * decode correctly, and drops out-of-range values instead of throwing.
+ */
+function numericEntity(cp: number): string {
+ return cp >= 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : ""
+}
+
function decodeHtmlEntities(text: string): string {
return text
.replace(/&amp;/g, "&")
@@ -75,7 +84,9 @@ function decodeHtmlEntities(text: string): string {
.replace(/&quot;/g, '"')
.replace(/&#39;/g, "'")
.replace(/&apos;/g, "'")
- .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(parseInt(code, 10)))
+ // Numeric character references: decimal (&#233;) and hexadecimal (&#xE9;).
+ .replace(/&#(\d+);/g, (_, dec) => numericEntity(parseInt(dec, 10)))
+ .replace(/&#[xX]([0-9a-fA-F]+);/g, (_, hex) => numericEntity(parseInt(hex, 16)))
.replace(/&nbsp;/g, " ")
}
diff --git a/.agents/skills/linkedin-search/cli/tests/parsing.test.ts b/.agents/skills/linkedin-search/cli/tests/parsing.test.ts
new file mode 100644
index 00000000..49d31157
--- /dev/null
+++ b/.agents/skills/linkedin-search/cli/tests/parsing.test.ts
@@ -0,0 +1,55 @@
+import { describe, test, expect } from "bun:test";
+import { parseJobCards, parseJobDetail } from "../src/helpers";
+
+// Minimal search-card markup: parseJobCards splits on the job-posting URN and
+// needs an id, a base-search-card__title, and a full-link. Everything else is
+// optional. We inject HTML entities into the title/company to exercise decoding.
+function searchCard(id: string, title: string, company = "Acme"): string {
+ return `<li>
+ <div data-entity-urn="urn:li:jobPosting:${id}">
+ <a class="base-card__full-link" href="https://www.linkedin.com/jobs/view/${id}"></a>
+ <h3 class="base-search-card__title">${title}</h3>
+ <h4 class="base-search-card__subtitle"><a href="https://www.linkedin.com/company/acme">${company}</a></h4>
+ </div>
+ </li>`;
+}
+
+describe("decodeHtmlEntities (via parseJobCards)", () => {
+ test("decodes hexadecimal numeric entities (&#xE9;)", () => {
+ const [card] = parseJobCards(searchCard("123", "Caf&#xE9; Manager"));
+ expect(card.title).toBe("Café Manager");
+ });
+
+ test("decodes uppercase-X hexadecimal entities (&#X...;)", () => {
+ const [card] = parseJobCards(searchCard("124", "Deb&#XFC;t Role")); // &#XFC; = ü
+ expect(card.title).toBe("Debüt Role");
+ });
+
+ test("still decodes decimal numeric entities (&#233;) — regression", () => {
+ const [card] = parseJobCards(searchCard("125", "Caf&#233; Lead"));
+ expect(card.title).toBe("Café Lead");
+ });
+
+ test("decodes supplementary-plane code points with fromCodePoint (&#128512;)", () => {
+ const [card] = parseJobCards(searchCard("126", "Growth &#128512;"));
+ expect(card.title).toBe("Growth 😀");
+ });
+
+ test("decodes hex supplementary-plane code points (&#x1F600;)", () => {
+ const [card] = parseJobCards(searchCard("127", "Growth &#x1F600;"));
+ expect(card.title).toBe("Growth 😀");
+ });
+
+ test("decodes hex entities in the company subtitle too", () => {
+ const [card] = parseJobCards(searchCard("128", "Engineer", "N&#xF8;rrebro ApS"));
+ expect(card.company).toBe("Nørrebro ApS");
+ });
+});
+
+describe("decodeHtmlEntities (via parseJobDetail)", () => {
+ test("decodes hex entities inside the job title", () => {
+ const html = `<h1 class="topcard__title">Se&#xF1;or Engineer</h1>`;
+ const job = parseJobDetail(html, "999");
+ expect(job.title).toBe("Señor Engineer");
+ });
+});