diff --git a/tools/gframework-config-tool/src/configValidation.js b/tools/gframework-config-tool/src/configValidation.js index 48c1c117..9eb7ddc4 100644 --- a/tools/gframework-config-tool/src/configValidation.js +++ b/tools/gframework-config-tool/src/configValidation.js @@ -719,11 +719,13 @@ function isValidCalendarDate(year, month, day) { return false; } - if (month < 1 || month > 12 || day < 1) { + if (year < 1 || year > 9999 || month < 1 || month > 12 || day < 1) { return false; } - const lastDay = new Date(Date.UTC(year, month, 0)).getUTCDate(); + const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0); + const monthDays = [31, isLeapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + const lastDay = monthDays[month - 1]; return day <= lastDay; } diff --git a/tools/gframework-config-tool/test/configValidation.test.js b/tools/gframework-config-tool/test/configValidation.test.js index b1d4f59b..a34723f0 100644 --- a/tools/gframework-config-tool/test/configValidation.test.js +++ b/tools/gframework-config-tool/test/configValidation.test.js @@ -667,6 +667,10 @@ test("validateParsedConfig should enforce supported string formats", () => { "type": "string", "format": "date" }, + "ancientReleaseDate": { + "type": "string", + "format": "date" + }, "publishedAt": { "type": "string", "format": "date-time" @@ -688,6 +692,7 @@ test("validateParsedConfig should enforce supported string formats", () => { `); const yaml = parseTopLevelYaml(` releaseDate: 2026-02-30 +ancientReleaseDate: 0000-01-01 publishedAt: 2026-04-11T08:30:00 contactEmail: boss.example.com catalogUri: /loot-table @@ -696,12 +701,13 @@ configId: 123e4567e89b12d3a456426614174000 const diagnostics = validateParsedConfig(schema, yaml); - assert.equal(diagnostics.length, 5); + assert.equal(diagnostics.length, 6); assert.match(diagnostics[0].message, /format 'date'|字符串格式“date”/u); - assert.match(diagnostics[1].message, /format 'date-time'|字符串格式“date-time”/u); - assert.match(diagnostics[2].message, /format 'email'|字符串格式“email”/u); - assert.match(diagnostics[3].message, /format 'uri'|字符串格式“uri”/u); - assert.match(diagnostics[4].message, /format 'uuid'|字符串格式“uuid”/u); + assert.match(diagnostics[1].message, /format 'date'|字符串格式“date”/u); + assert.match(diagnostics[2].message, /format 'date-time'|字符串格式“date-time”/u); + assert.match(diagnostics[3].message, /format 'email'|字符串格式“email”/u); + assert.match(diagnostics[4].message, /format 'uri'|字符串格式“uri”/u); + assert.match(diagnostics[5].message, /format 'uuid'|字符串格式“uuid”/u); }); test("validateParsedConfig should accept supported string formats", () => {