fix(schema): case the present label by its language only

page.locale accepts any string. A malformed tag such as "de-DE-" made toLocaleUpperCase throw a RangeError, so parseResumeData failed and the resume could not load. The language code always comes from the parser's word list, so it is a valid tag.
This commit is contained in:
Amruth Pillai
2026-09-29 22:10:14 +02:00
parent 461d3c4e64
commit 03c3a88841
2 changed files with 6 additions and 1 deletions
+4
View File
@@ -96,6 +96,10 @@ describe("getPresentLabel", () => {
expect(getPresentLabel("de-DE")).toBe("Heute");
expect(getPresentLabel("xx-XX")).toBe("Present");
});
it("reads a malformed locale tag by its language instead of throwing", () => {
expect(getPresentLabel("de-DE-")).toBe("Heute");
});
});
describe("upgradeResumeDates", () => {
+2 -1
View File
@@ -55,7 +55,8 @@ export function getPresentLabel(locale: string): string {
const word = ONGOING_TOKENS_BY_LANGUAGE[language]?.[0];
if (!word) return "Present";
return word.charAt(0).toLocaleUpperCase(locale) + word.slice(1);
// Case the word by its language alone: `locale` can be a malformed tag ("de-DE-") that throws a RangeError.
return word.charAt(0).toLocaleUpperCase(language) + word.slice(1);
}
const toEndpoint = (value: YearMonth): PeriodEndpoint => {