Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

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

PerryLinkd3131e097761
diff --git a/packages/import/src/json-resume.test.ts b/packages/import/src/json-resume.test.ts
index 3e8a12019..434abf91f 100644
--- a/packages/import/src/json-resume.test.ts
+++ b/packages/import/src/json-resume.test.ts
@@ -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.
diff --git a/packages/import/src/json-resume.tsx b/packages/import/src/json-resume.tsx
index 591282911..d344f4106 100644
--- a/packages/import/src/json-resume.tsx
+++ b/packages/import/src/json-resume.tsx
@@ -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)",
);