fix: reject invalid cron epoch timestamps · openclaw/openclaw@ed9299a
openclaw
·
2026-05-29
·
via Recent Commits to openclaw:main
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|
@@ -244,6 +244,10 @@ describe("parseAt", () => {
|
244 | 244 | expect(parseAt("+30m")).toBe("2026-05-25T00:30:00.000Z"); |
245 | 245 | expect(parseAt("30m")).toBe("2026-05-25T00:30:00.000Z"); |
246 | 246 | }); |
| 247 | + |
| 248 | +it("rejects out-of-range epoch milliseconds", () => { |
| 249 | +expect(parseAt(String(Number.MAX_SAFE_INTEGER))).toBeNull(); |
| 250 | +}); |
247 | 251 | }); |
248 | 252 | |
249 | 253 | describe("getCronChannelOptions", () => { |
|
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { parseAbsoluteTimeMs } from "./parse.js"; |
| 3 | + |
| 4 | +describe("parseAbsoluteTimeMs", () => { |
| 5 | +it("parses positive epoch milliseconds", () => { |
| 6 | +expect(parseAbsoluteTimeMs("1700000000000")).toBe(1_700_000_000_000); |
| 7 | +}); |
| 8 | + |
| 9 | +it("rejects digit-only timestamps outside the Date range", () => { |
| 10 | +expect(parseAbsoluteTimeMs(String(Number.MAX_SAFE_INTEGER))).toBeNull(); |
| 11 | +}); |
| 12 | +}); |
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { parseStrictPositiveInteger } from "../infra/parse-finite-number.js"; |
| 2 | + |
1 | 3 | const ISO_TZ_RE = /(Z|[+-]\d{2}:?\d{2})$/i; |
2 | 4 | const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/; |
3 | 5 | const ISO_DATE_TIME_RE = /^\d{4}-\d{2}-\d{2}T/; |
@@ -21,10 +23,11 @@ export function parseAbsoluteTimeMs(input: string): number | null {
|
21 | 23 | return null; |
22 | 24 | } |
23 | 25 | if (/^\d+$/.test(raw)) { |
24 | | -const n = Number(raw); |
25 | | -if (Number.isFinite(n) && n > 0) { |
26 | | -return Math.floor(n); |
| 26 | +const n = parseStrictPositiveInteger(raw); |
| 27 | +if (n !== undefined && Number.isFinite(new Date(n).getTime())) { |
| 28 | +return n; |
27 | 29 | } |
| 30 | +return null; |
28 | 31 | } |
29 | 32 | const parsed = Date.parse(normalizeUtcIso(raw)); |
30 | 33 | return Number.isFinite(parsed) ? parsed : null; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。