diff --git a/.agents/skills/linkedin-search/cli/src/helpers.ts b/.agents/skills/linkedin-search/cli/src/helpers.ts index 56308b3..19e0200 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(/&/g, "&") @@ -75,7 +84,9 @@ function decodeHtmlEntities(text: string): string { .replace(/"/g, '"') .replace(/'/g, "'") .replace(/'/g, "'") - .replace(/(\d+);/g, (_, code) => String.fromCharCode(parseInt(code, 10))) + // Numeric character references: decimal (é) and hexadecimal (é). + .replace(/(\d+);/g, (_, dec) => numericEntity(parseInt(dec, 10))) + .replace(/[xX]([0-9a-fA-F]+);/g, (_, hex) => numericEntity(parseInt(hex, 16))) .replace(/ /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 0000000..49d3115 --- /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 `