fix(import): reject out-of-range months that render as "undefined" (#3527)

Co-authored-by: Amruth Pillai <im.amruth@gmail.com>
This commit is contained in:
PerryLink
2026-09-21 19:47:02 +02:00
committed by GitHub
co-authored by Amruth Pillai
parent 28d0170b05
commit d3131e0977
2 changed files with 24 additions and 1 deletions
+23
View File
@@ -13,6 +13,29 @@ describe("parseJSONResume", () => {
expect(() => parseJSONResume(invalid)).toThrow();
});
it.each([
"2024-00",
"2024-13",
"2024-19",
"2024-00-01",
"2024-13-01",
"2024-01-00",
"2024-01-32",
"2024-1",
"2024-1-5",
])("rejects the malformed date %s and names the field", (startDate) => {
const json = JSON.stringify({ work: [{ name: "Acme", position: "Engineer", startDate }] });
expect(() => parseJSONResume(json)).toThrow(/work\.0\.startDate \(Must be a valid ISO 8601 date/);
});
it.each(["2024", "2024-01", "2024-12", "2024-02-29", "1999-12-31"])(
"still accepts the valid date %s",
(startDate) => {
const json = JSON.stringify({ work: [{ name: "Acme", position: "Engineer", startDate }] });
expect(() => parseJSONResume(json)).not.toThrow();
},
);
it("imports an empty JSON Resume into a baseline ResumeData", () => {
const result = parseJSONResume("{}");
// Defaults preserve a name field even when unset by input.
+1 -1
View File
@@ -23,7 +23,7 @@ const createItemWebsite = (url?: string, label?: string) => ({
const iso8601 = z
.string()
.regex(
/^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$/,
/^([1-2][0-9]{3}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])|[1-2][0-9]{3}-(?:0[1-9]|1[0-2])|[1-2][0-9]{3})$/,
"Must be a valid ISO 8601 date (YYYY, YYYY-MM, or YYYY-MM-DD)",
);