mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 00:26:26 +00:00
fix(jobindex-search): decode hex HTML entities in CLI output (#56)
decodeHtmlEntities (duplicated in src/helpers.ts and src/commands/detail.ts) only handled decimal numeric character references (é); the equally valid hexadecimal form (é) fell through undecoded and surfaced as raw text in titles, companies, locations and descriptions. This bites Danish content especially (ae/o/aa often arrive as entities). It also used String.fromCharCode, which corrupts supplementary-plane code points (e.g. emoji, U+1F600). Add a hexadecimal numeric-entity rule and route both decimal and hex through a fromCodePoint-based helper with a valid-range guard, in both copies. Add network-free unit tests via the exported parseJobCards.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { describe, test, expect } from "bun:test";
|
||||
import { parseJobCards } from "../src/helpers";
|
||||
|
||||
// Minimal jobad-wrapper markup: parseJobCards splits on `jobad-wrapper-<id>`
|
||||
// and reads the title from the <h4><a href>…</a></h4> and the company from the
|
||||
// jix-toolbar-top__company link. We inject HTML entities to exercise decoding.
|
||||
function card(id: string, title: string, company = "Acme A/S"): string {
|
||||
return `<div id="jobad-wrapper-${id}" class="PaidJob">
|
||||
<h4><a href="https://www.jobindex.dk/jobannonce/${id}">${title}</a></h4>
|
||||
<div class="jix-toolbar-top__company">
|
||||
<a href="https://www.jobindex.dk/virksomhed/acme">${company}</a>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
describe("decodeHtmlEntities (via parseJobCards)", () => {
|
||||
test("decodes hexadecimal numeric entities (ø -> ø)", () => {
|
||||
const [c] = parseJobCards(card("h1", "Smørrebro Chef"));
|
||||
expect(c.title).toBe("Smørrebro Chef");
|
||||
});
|
||||
|
||||
test("decodes uppercase-X hexadecimal entities (æ -> æ)", () => {
|
||||
const [c] = parseJobCards(card("h2", "Kære Kollega"));
|
||||
expect(c.title).toBe("Kære Kollega");
|
||||
});
|
||||
|
||||
test("still decodes decimal numeric entities (å -> å) — regression", () => {
|
||||
const [c] = parseJobCards(card("h3", "århus Lead"));
|
||||
expect(c.title).toBe("århus Lead");
|
||||
});
|
||||
|
||||
test("decodes supplementary-plane code points with fromCodePoint (😀)", () => {
|
||||
const [c] = parseJobCards(card("h4", "Growth 😀"));
|
||||
expect(c.title).toBe("Growth 😀");
|
||||
});
|
||||
|
||||
test("decodes hex supplementary-plane code points (😀)", () => {
|
||||
const [c] = parseJobCards(card("h5", "Growth 😀"));
|
||||
expect(c.title).toBe("Growth 😀");
|
||||
});
|
||||
|
||||
test("decodes hex entities in the company name too", () => {
|
||||
const [c] = parseJobCards(card("h6", "Engineer", "Nørrebro ApS"));
|
||||
expect(c.company).toBe("Nørrebro ApS");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user