Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat: enhance HTML entity decoding in text processing and resume conversion
Khuram Niaz9a44052bd42a
diff --git a/__tests__/ats-runner.spec.ts b/__tests__/ats-runner.spec.tsindex 742061d..99381fe 100644--- a/__tests__/ats-runner.spec.ts+++ b/__tests__/ats-runner.spec.ts@@ -169,4 +169,38 @@ describe("runAutomation (lever)", () => {expect(result.errorMessage).toBe("no_companies");expect((searchLeverJobs as any).mock.calls.length).toBe(0);});++ it("strips HTML and decodes entities from the resume before matching", async () => {+ (prisma.resume.findUnique as any).mockResolvedValue({+ id: "resume1",+ title: "My Resume",+ ContactInfo: null,+ ResumeSections: [+ {+ sectionType: "experience",+ workExperiences: [+ {+ description: "<p>Sales & Marketing</p>",+ startDate: new Date("2020-01-01"),+ endDate: null,+ Company: { label: "Acme" },+ jobTitle: { label: "Engineer" },+ location: { label: "Remote" },+ },+ ],+ },+ ],+ });+ (searchLeverJobs as any).mockResolvedValue({+ jobs: [makeJob("Frontend Engineer", "React")],+ errors: [],+ });++ await runAutomation(leverAutomation);++ const prompt = (generateText as any).mock.calls[0][0].prompt as string;+ expect(prompt).toContain("Sales & Marketing");+ expect(prompt).not.toContain("&");+ expect(prompt).not.toContain("<p>");+ });});diff --git a/__tests__/taskDescription.spec.ts b/__tests__/taskDescription.spec.tsindex 6d59072..e3aa590 100644--- a/__tests__/taskDescription.spec.ts+++ b/__tests__/taskDescription.spec.ts@@ -25,6 +25,12 @@ describe("toPlainText", () => {it("decodes non-breaking spaces to whitespace", () => {expect(toPlainText("<p>a b</p>")).toBe("a b");});++ it("decodes HTML entities like & back to their characters", () => {+ expect(toPlainText("<p>Sales & Marketing</p>")).toBe(+ "Sales & Marketing",+ );+ });});describe("hasDescription", () => {diff --git a/__tests__/text-processing.spec.ts b/__tests__/text-processing.spec.tsindex 835fce0..b4eb760 100644--- a/__tests__/text-processing.spec.ts+++ b/__tests__/text-processing.spec.ts@@ -65,6 +65,18 @@ describe("removeHtmlTags", () => {const result = removeHtmlTags(html);expect(result).toContain("• Content");});++ it("decodes HTML entities left over from tag stripping", () => {+ const html = "<p>Baker Hughes, & EPIROC</p>";+ const result = removeHtmlTags(html);+ expect(result).toBe("Baker Hughes, & EPIROC");+ });++ it("decodes common named and numeric entities", () => {+ const html = "<p><tag> "quoted" 'it's'</p>";+ const result = removeHtmlTags(html);+ expect(result).toBe('<tag> "quoted" \'it\'s\'');+ });});describe("normalizeWhitespace", () => {diff --git a/src/lib/ai/tools/text-processing.ts b/src/lib/ai/tools/text-processing.tsindex 65ef229..392887a 100644--- a/src/lib/ai/tools/text-processing.ts+++ b/src/lib/ai/tools/text-processing.ts@@ -6,17 +6,39 @@// HTML AND WHITESPACE NORMALIZATION+const NAMED_ENTITIES: Record<string, string> = {+ "<": "<",+ ">": ">",+ """: '"',+ "'": "'",+ "'": "'",+ " ": " ",+ "&": "&", // keep ampersand last so it does not undo other entities+};++const decodeHtmlEntities = (text: string): string => {+ let out = text.replace(/&#(\d+);/g, (_, code) =>+ String.fromCodePoint(Number(code)),+ );+ for (const [entity, char] of Object.entries(NAMED_ENTITIES)) {+ out = out.split(entity).join(char);+ }+ return out;+};+export const removeHtmlTags = (description: string | undefined): string => {if (!description) return "";- return description- .replace(/<li[^>]*>/gi, "• ")- .replace(/<\/(li|p|div|br)[^>]*>/gi, "\n")- .replace(/<br\s*\/?>/gi, "\n")- .replace(/<[^>]+>/g, " ")- .replace(/\s+/g, " ")- .replace(/\n\s*\n/g, "\n")- .trim();+ return decodeHtmlEntities(+ description+ .replace(/<li[^>]*>/gi, "• ")+ .replace(/<\/(li|p|div|br)[^>]*>/gi, "\n")+ .replace(/<br\s*\/?>/gi, "\n")+ .replace(/<[^>]+>/g, " ")+ .replace(/\s+/g, " ")+ .replace(/\n\s*\n/g, "\n")+ .trim(),+ );};export const normalizeWhitespace = (text: string): string => {diff --git a/src/lib/scraper/runner.ts b/src/lib/scraper/runner.tsindex 86950d7..02672c5 100644--- a/src/lib/scraper/runner.ts+++ b/src/lib/scraper/runner.ts@@ -1211,7 +1211,7 @@ async function convertResumeForMatch(for (const section of resume.ResumeSections) {if (section.sectionType === "summary" && section.summary?.content) {- parts.push("## SUMMARY", section.summary.content);+ parts.push("## SUMMARY", removeHtmlTags(section.summary.content));}if (@@ -1224,7 +1224,7 @@ async function convertResumeForMatch(`Company: ${exp.Company.label}`,`Job Title: ${exp.jobTitle.label}`,`Location: ${exp.location.label}`,- `Description: ${exp.description}`,+ `Description: ${removeHtmlTags(exp.description)}`,"",);}@@ -1237,7 +1237,7 @@ async function convertResumeForMatch(`Institution: ${edu.institution}`,`Degree: ${edu.degree}`,`Field: ${edu.fieldOfStudy}`,- edu.description ? `Description: ${edu.description}` : "",+ edu.description ? `Description: ${removeHtmlTags(edu.description)}` : "","",);}diff --git a/src/lib/tasks/description.ts b/src/lib/tasks/description.tsindex e808cc3..728df27 100644--- a/src/lib/tasks/description.ts+++ b/src/lib/tasks/description.ts@@ -7,6 +7,11 @@ export function toPlainText(html?: string | null): string {return html.replace(/<[^>]+>/g, " ").replace(/ /g, " ")+ .replace(/</g, "<")+ .replace(/>/g, ">")+ .replace(/"/g, '"')+ .replace(/'/g, "'")+ .replace(/&/g, "&").replace(/\s+/g, " ").trim();}