{"record":{"id":"536436d3a8aa2098","repo":"DIYgod/RSSHub","slug":"invalid-enddate-format-expected-yyyy-mm-dd","errorCode":null,"errorMessage":"Invalid endDate format. Expected YYYY-MM-DD","messagePattern":"Invalid endDate format\\. Expected YYYY-MM-DD","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"error","filePath":"lib/routes/szse/disclosure/listed-notice.ts","lineNumber":48,"sourceCode":"    const queries: Record<string, string> = {\n        stock: '',\n        beginDate: '',\n        endDate: '',\n    };\n    if (query) {\n        for (const pair of query.split('&')) {\n            const [key, value] = pair.split('=', 2);\n            if (key) {\n                queries[key] = value;\n            }\n        }\n    }\n    if (queries.beginDate && !isValidDate(queries.beginDate)) {\n        throw new Error('Invalid beginDate format. Expected YYYY-MM-DD');\n    }\n    if (queries.endDate) {\n        if (!isValidDate(queries.endDate)) {\n            throw new Error('Invalid endDate format. Expected YYYY-MM-DD');\n        }\n    } else if (queries.beginDate) {\n        // 如果只提供了开始日期，则将结束日期设置为开始日期\n        queries.endDate = queries.beginDate;\n    }\n    const baseUrl = 'https://www.szse.cn';\n    const staticBaseUrl = 'https://disc.static.szse.cn';\n    const apiUrl: string = new URL('api/disc/announcement/annList', baseUrl).href;\n    const targetUrl: string = new URL(`disclosure/listed/notice${category}`, baseUrl).href;\n\n    const targetResponse = await ofetch(targetUrl);\n    const $: CheerioAPI = load(targetResponse);\n    const language = $('html').attr('lang') ?? 'zh-CN';\n    const response = await ofetch(apiUrl, {\n        method: 'POST',\n        body: {\n            stock: queries.stock ? [queries.stock] : [],\n            seDate: [queries.beginDate, queries.endDate],","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/szse/disclosure/listed-notice.ts#L30-L66","documentation":"Thrown by szse/disclosure/listed-notice.ts:48 via `throw new Error(...)` (NOT an InvalidParameterError) when an explicit endDate fails isValidDate (strict YYYY-MM-DD + real-calendar). Only checked when endDate is truthy. If endDate is OMITTED but beginDate is set, the code silently copies beginDate into endDate (line 52) — no error — so this fires only on an explicit-but-malformed endDate.","triggerScenarios":"endDate=2025-02-30, endDate=2025/02/03, endDate=2025-13-01, endDate=2025-2-3 — any explicit value failing the strict date check.","commonSituations":"Inconsistent date formatting between beginDate and endDate; copying from a different locale format;endDate accidentally before beginDate is NOT caught here (the upstream API may reject it later).","solutions":["Use strict YYYY-MM-DD with leading zeros for endDate.","Omit endDate entirely to default it to beginDate (single-day query)."],"exampleFix":"// before\nGET /szse/disclosure/listed/notice/beginDate=2025-02-03&endDate=2025-2-30\n// after\nGET /szse/disclosure/listed/notice/beginDate=2025-02-03&endDate=2025-02-28","handlingStrategy":"validation","validationCode":"function isValidDate(dateString: string): boolean {\n  if (!/^\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])$/.test(dateString)) {\n    return false;\n  }\n  const [y, m, d] = dateString.split('-').map(Number);\n  const date = new Date(y, m - 1, d);\n  return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;\n}\n\n// Omit endDate to default it to beginDate; otherwise validate strictly.\nif (endDate && !isValidDate(endDate)) {\n  // reject client-side\n}","typeGuard":"function isStrictYmd(s: string): s is string {\n  if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(s)) return false;\n  const [y, m, d] = s.split('-').map(Number);\n  const date = new Date(y, m - 1, d);\n  return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;\n}","tryCatchPattern":null,"preventionTips":["Use strict YYYY-MM-DD with leading zeros for endDate.","Omit endDate when you want a single-day query (it defaults to beginDate).","Keep the same format for beginDate and endDate to avoid mismatches."],"tags":["invalid-parameter","date-validation","finance","szse","wrong-error-type"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}